Forums / General / how to get to 'location' of Link class using treemenu

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