Forums / Developer / simple variable problem

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>

eZ debug

Timing: Jan 18 2025 20:49:27
Script start
Timing: Jan 18 2025 20:49:27
Module start 'content'
Timing: Jan 18 2025 20:49:28
Module end 'content'
Timing: Jan 18 2025 20:49:28
Script end

Main resources:

Total runtime1.1006 sec
Peak memory usage4,096.0000 KB
Database Queries217

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0085 587.7031180.8438
Module start 'content' 0.00850.9167 768.5469673.0078
Module end 'content' 0.92510.1754 1,441.5547344.4453
Script end 1.1005  1,786.0000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.4083210.0002
Check MTime0.00160.1430210.0001
Mysql Total
Database connection0.00120.110510.0012
Mysqli_queries1.001290.97102170.0046
Looping result0.00270.24302150.0000
Template Total1.062896.620.5314
Template load0.00240.215020.0012
Template processing1.060496.347520.5302
Template load and register function0.00020.021310.0002
states
state_id_array0.00120.106810.0012
state_identifier_array0.00180.160820.0009
Override
Cache load0.00210.1909730.0000
Sytem overhead
Fetch class attribute can translate value0.00150.137640.0004
Fetch class attribute name0.00160.1448110.0001
XML
Image XML parsing0.00100.086640.0002
class_abstraction
Instantiating content class attribute0.00000.0034140.0000
General
dbfile0.00210.1904270.0001
String conversion0.00000.000730.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
10content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
22content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 54
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs