simple variable problem

Author Message

Rinze Cats

Wednesday 21 April 2004 3:31:47 am

I have a variable problem that is bugging me

I have a general .tpl that I use only for my homepage. It loops through alle related objects of the homepage (articles) and displays an introduction and link to each article. This is working fine.

However. The articles can have an object relation (defined with in the article class), which point to an image. If so, it should be displayed. I cannot properly instantiate this image object! please help, this should be easy. I keep getting a namespace error.

I want to fetch the object, assign is to a variable and use the variable to access the object and it's attributes

{section name=Related loop=$current_node.object.related_contentobject_array}
{* loop through all related objects *}
{* first get the parent to define placement on the page*}
{set-block name=homepageContent scope=global variable=parentID}
{$Related:item.parent_nodes.0}
{/set-block}
{switch match=$homepageContent:parentID}
{case match=49} {* categorie 1 *}
{set-block name=homepageContent scope=global variable=content}
{$Related:item.data_map.introductie.content}
{/set-block}
{set-block name=homepageContent scope=global variable=contentlink}
<a href={$Related:item.main_node.url_alias|ezurl} title=" ">more...</a>
{/set-block}
{* ************ *}
{* and now I need to fetch the image and put it in an object variable*}


{let name=homePageContent object=fetch( 'content', 'object', hash( 'object_id', $Related:item.data_map.thumbnail.content.id ))}
{/let}
{/case}
{/switch}

..can't figure it out

Alex Jones

Wednesday 21 April 2004 6:27:06 am

Hrrrm, I'm not 100% positive on this, but I think you are trying to call the variable incorrectly. You are setting the variable with:

{set-block name=homepageContent scope=global variable=parentID}
{$Related:item.parent_nodes.0}
{/set-block}

And trying to access it with: <i>$homepageContent:parentID</i>

Try calling it with <i>$parentID</i> only and see if that works. Also, try setting the scope to <i>root</i> instead of global. Here is an example of code that works on my installation, it is a bit different than what you are trying to do, but it may help:

{set-block scope=root variable=KeyCode}
  {let parentnode=fetch('content','node',hash(node_id,$DesignKeys:used.parent_node))}
    {$parentnode.data_map.keycode.data_text}
  {/let}
{/set-block}

{section show=ne($KeyCode,'0')}{$KeyCode} - {/section}

Hope this helps,

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Rinze Cats

Wednesday 21 April 2004 6:52:23 am

Hi alex, thanx for the reply

I will try your code suggestion and change the variable scope to root.
however, the part about the parentid per se is not causing the problem ( i think)
homePageContent.parentid used in the case if functional (although the code might not be ideal. Using the homePageContent namespace makes it simple to access the variables in the rest of the pages code.
the real problem lies in the part

{* ************ *}
{* and now I need to fetch the image and put it in an object variable*}

{let name=homePageContent object=fetch( 'content', 'object', hash( 'object_id', $Related:item.data_map.thumbnail.content.id ))}

the let defined here is not working. If I use the fetch in a set-block, like I do with the other two attributes, it actually returns something like "(ezContentobject) ... "
Can't remember exact, but it looks like it does fetch the object i want. The problem is that a set-block only returns strings, preventing me from actually using the attributes within the object. So I need a working alternative for

set-block name=homepageContent scope=global variable=myobject>
{fetch( 'content', 'object', hash( 'object_id', $Related:item.data_map.thumbnail.content.id ))}
{/set-block}

because this returns the string and I want to place the object in a variable, in my homepageContent namespace.

greetz
rinze

Alex Jones

Wednesday 21 April 2004 9:02:30 am

Hrrrm, I'm not sure about this one. Sorry. Hopefully someone else can help out.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Dominik Pich

Thursday 22 April 2004 12:41:55 am

a let to init (all) the variable(s) and a set to fetch the real content.

Rinze Cats

Thursday 22 April 2004 1:03:50 am

could you possibly supply a small example to illustrate this? Preferably using a namespace as well. I have already spend hours on somethign as trivial as this ;-)

how do I for instance initialize an object using {let}. Do I have to assign a value of can I just say
<i>{let name=homepageContent myobject}</i>
....
<i>{let myobject = fetch (etc...}</i>

and then use the code by saying:

{$homepageContent:myobject.name}

?

thanx for the help!

Dominik Pich

Thursday 22 April 2004 1:18:48 am

{let name=data var=false}
{set var=fetch(...)}
{$data:var}
{/let}

Alex Jones

Thursday 22 April 2004 6:07:53 am

Oh yeah! I can't believe I missed that. Nice catch Dominik.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Rinze Cats

Thursday 22 April 2004 7:17:34 am

hi guys,

this solved my problem indeed. i knew it was supposed to be easy! I also implemented some code to check whether an image has been added. If so, fetch it! First I added the 'let' to my section

{section name=Related loop=$current_node.object.related_contentobject_array}
{let myobject=false}

then I added the following logic

{* get the object relation. *}
{* from the related object, extract the image and the alternative text and create an image tag (if exists*}
  {* check if homepage picture is available, if so proces it *}
  {section show=ne($Related:item.data_map.thumbnail.content.id,'')}
  {set myobject=fetch( 'content', 'object', hash( 'object_id', $Related:item.data_map.thumbnail.content.id ))}
  {set-block name=homepageContent scope=global variable=mythumbnail}
  {* check if the object has been set, if so: create the image tag*}
  {section show=ne($Related:myobject,'')}
	<img src="{$Related:myobject.main_node.data_map.image.content.small.url}" alt="{$Related:myobject.main_node.data_map.caption.content.output.output_text}">
  {section-else}
  {/section}
  {/set-block}
  {section-else}
{/section}

then I added
<i>{$homepageContent:mythumbnail}</i> where I want to show the thumbnail.

I guess the conditional part needs some improvement. suggestions are welcome!

thanx again for the help!
rinze

Alex Jones

Thursday 22 April 2004 7:38:49 am

Well, one quick note: you don't need to use those two instances of <i>{section-else}</i> as you are not executing any other code. So you can tighten it up to look like:

{section show=ne($Related:item.data_map.thumbnail.content.id,'')}
  {set myobject=fetch( 'content', 'object', hash( 'object_id', $Related:item.data_map.thumbnail.content.id ))}
  {set-block name=homepageContent scope=global variable=mythumbnail}
    {section show=ne($Related:myobject,'')}
      <img src="{$Related:myobject.main_node.data_map.image.content.small.url}" alt="{$Related:myobject.main_node.data_map.caption.content.output.output_text}">
    {/section}
  {/set-block}
{/section}

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 23:19:03
Script start
Timing: Jan 18 2025 23:19:03
Module start 'layout'
Timing: Jan 18 2025 23:19:03
Module start 'content'
Timing: Jan 18 2025 23:19:03
Module end 'content'
Timing: Jan 18 2025 23:19:03
Script end

Main resources:

Total runtime0.0218 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 587.9063152.6250
Module start 'layout' 0.00750.0037 740.531339.4453
Module start 'content' 0.01120.0083 779.9766105.4297
Module end 'content' 0.01950.0022 885.406346.3047
Script end 0.0217  931.7109 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002712.4815140.0002
Check MTime0.00125.3313140.0001
Mysql Total
Database connection0.00136.033510.0013
Mysqli_queries0.003817.621430.0013
Looping result0.00000.105010.0000
Template Total0.00188.110.0018
Template load0.00094.229810.0009
Template processing0.00083.807610.0008
Override
Cache load0.00062.968610.0006
General
dbfile0.00209.307380.0003
String conversion0.00000.045940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs