how to get to 'location' of Link class using treemenu

Author Message

Michal Slocinski

Monday 17 March 2008 11:46:51 pm

Hi,

I'm trying to generate menu for my top-level content node which has children in the form of articles, folders and also instances of Link class. Using treemenu operator (http://ez.no/doc/ez_publish/technical_manual/3_10/reference/template_operators/miscellaneous/treemenu) I've code similar to that:

{def $mainMenu=treemenu( $module_result.path, $module_result.node_id ) }
{foreach $mainMenu as $menu}
<a href={$menu.url|ezurl}>{$menu.text}</a>
{/foreach}
{undef $mainMenu}

The problem is that for Link class instances, URL which is generated points to object instance instead of 'location' attribute (which is what I would expect).

Now, simple workaround is to fetch each of nodes, check if it is instance of Link class and in that case create href pointing to {$node.data_map.location.content} however I just can't imagine such simple use case has to be solved in that way.

Any suggestions are appreciated.

Michal

André R.

Tuesday 18 March 2008 2:28:06 am

How would you rather like to solve it?

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Michal Slocinski

Tuesday 18 March 2008 12:02:21 pm

well, ideally

{$menu.url}

Should be context aware and in case when object is Link class instance it should just return location instead of link to that node. This naturally could be configurable.

Less perfect solution, but what would also save some typing, is if structures returned by treemenu operator would contain ezcontentobjecttreenode object so I wouldn't have to fetch it manually.

Another useful feature of teemenu operator would be to allow for more complex filtering like in case fetch/list operator. It happens frequently that I need to filter elements out by priority. This also cannot be easily achieved at the moment so again I need to fetch node object manually, compare priority and do something basing on the outcome of comparison.

I think generally fetch/list operator is really robust, would be really helpful to have treemenu little closer to that one.

One more question not completely related to this topic. I'm not familiar with implementing new operators, but from what I saw I think you need to always implement it in PHP. Is there a way to implement some operator using template language? I'm thinking of some kind of operator I could implement which would internally use treemenu but do some stuff around it like what I described above with URLs or priorities and reuse it later in different places. Would be nice to be able to do it using template language as I (and probably most of other people) know it better than internal PHP API of eZ publish.

André R.

Tuesday 18 March 2008 1:23:19 pm

Well the node.url is the url of the node, even if it is a link object it still has it right to have a url / path / location.
I don't think it would have been a good thing if you suddenly couldn't link to some object because some of it attributes had 'magic functionality'.

When it comes to template operators, they need to be written in php, but that doesn't mean you can't reuse the treemenu operator from with in php or make a custom copy of it that does whatever you want it to do. The best way to learn template operators is to take a look at the ones in the contribution area or on projects.ez.no

If you want to reuse code with only template code you can always use includes.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Michal Slocinski

Tuesday 18 March 2008 2:07:16 pm

thanks for answers, I understand that implementing such functionality would require probably bigger redesign

I'm going to play more with includes but anyway - improving treemenu robustness in terms of filtering / fetching nodes out-of-the-box would be good improvement

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 31 2025 06:23:44
Script start
Timing: Jan 31 2025 06:23:44
Module start 'layout'
Timing: Jan 31 2025 06:23:44
Module start 'content'
Timing: Jan 31 2025 06:23:44
Module end 'content'
Timing: Jan 31 2025 06:23:44
Script end

Main resources:

Total runtime0.0152 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.0057 588.2578151.2266
Module start 'layout' 0.00570.0021 739.484436.6953
Module start 'content' 0.00790.0061 776.179794.2813
Module end 'content' 0.01400.0012 870.460937.9922
Script end 0.0152  908.4531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002214.5834140.0002
Check MTime0.00106.5190140.0001
Mysql Total
Database connection0.00106.581710.0010
Mysqli_queries0.002113.533730.0007
Looping result0.00000.072210.0000
Template Total0.00095.910.0009
Template load0.00074.441710.0007
Template processing0.00021.408910.0002
Override
Cache load0.00053.040610.0005
General
dbfile0.00128.146080.0002
String conversion0.00000.037740.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