Page 1 of 1
Adding link on section header in sitemap: How to?
Posted: Wed Jun 07, 2017 7:51 pm
by jakovbak
Hello everyone!
Is it possible to add a link on section headers in sitemap to point to their first child pages?
I was playing around with sitemap template but ended up with a mess on my site so I gave up on experimenting with template and admitting I'm still not familiar with smarty...

Thank you in advance for any tip or suggestion!
Best regards,
Jakovbak
Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 8:35 am
by velden
I assume you're using the Navigator module and template?
A section header node has a child node. You can just get the url of the first item in that child node.
Hint:
Code: Select all
...
{if $node->type == 'sectionheader'}
{* section header *}
<li class="sectionheader{if $node->parent} activeparent{/if}">
{if isset($node->children)}<a href="{$node->children.0->url}">{$node->menutext}</a>{else}
{$node->menutext}
{/if}
{if isset($node->children)}
<!-- {$node->children|print_r} -->
{include file=$smarty.template nodes=$node->children depth=$depth+1}
...
Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 9:03 am
by jakovbak
Yes, Velden, I'm using Navigator module and template. The problem is my lack of knowledge of smarty syntax... I have tried to get the url of the first child but only to find myself breaking the page. Luckily, I had my working template in a safe place so once I have placed it back everything was ok.
I was looking at this as an example:
Code: Select all
<a{do_footer_class classes=$href_class} href='{$node->url}'{if $node->target != ''} target='{$node->target}'{/if}>{$node->menutext}</a>
and tried to figure out how to use it and tweak it for this:
Code: Select all
{$list_class[] = 'sectionheader'}
<li{do_footer_class classes=$list_class}><span>{$node->menutext}</span>
{if isset($node->children)}
{Simplex_footer_menu data=$node->children depth=$depth+1}
{/if}
</li>
Obviously, it was a task way above me... This approach worked for some (much) simpler situations but pure logic thinking without basic knowledge won't get the job done in cases like this.

Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 9:10 am
by velden
Note I later added an example piece of code to my earlier post. It should help you finding the url of the first child.
Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 10:51 am
by jakovbak
Here's what i did with the code you provided (entire template):
Code: Select all
{strip}
<div class="container">
<div class="row">
{$main_id = ' id=\'footer-menu\''}
{function do_footer_class}
{if count($classes) > 0} class='{implode(' ',$classes)}'{/if}
{/function}
{function name='Simplex_footer_menu' depth='1'}
<ul{$main_id}{if isset($ul_class) && $ul_class != ''} class="{$ul_class} col-md-12"{/if}>
{$main_id = ''}
{$ul_class = ''}
{foreach $data as $node}
{* setup classes for the anchor and list item *}
{$list_class = []}
{$href_class = []}
{if $node->current || $node->parent}
{* this is the current page *}
{$list_class[] = 'current'}
{$href_class[] = 'current'}
{/if}
{if $node->children_exist}
{$list_class[] = 'parent'}
{/if}
{* build the menu item node *}
{if $node->type == 'sectionheader'}
{* section header *}
<li class="sectionheader{if $node->parent} activeparent{/if}">
{if isset($node->children)}<a href="{$node->children.0->url}">{$node->menutext}</a>
{else}
{$node->menutext}
{/if}
{if isset($node->children)}
<!-- {$node->children|print_r} -->
{include file=$smarty.template nodes=$node->children depth=$depth+1}
{/if}
</li>
{else if $node->type == 'separator'}
{$list_class[] = 'separator'}
<li{do_footer_class classes=$list_class}'><hr class='separator'/></li>
{else}
{* regular item *}
<li{do_footer_class classes=$list_class}>
<a{do_footer_class classes=$href_class} href='{$node->url}'{if $node->target != ''} target='{$node->target}'{/if}>{$node->menutext}</a>
{if isset($node->children)}
{Simplex_footer_menu data=$node->children depth=$depth+1}
{/if}
</li>
{/if}
{/foreach}
</ul>
{/function}
{if isset($nodes)}
{Simplex_footer_menu data=$nodes depth='0' ul_class='cf'}
{/if}
</div>
</div>
{/strip}
Here is the link to the page where sitemap is:
http://www.adriaticsolution.hr/index.php?page=marine
As you can see if you hover on "Tech & Repairs" (for example), it looks like the rest of the links but there is no link on it ("Tech & Repairs" is one of those section headers I'm trying to solve).
However, there is a difference between this template and original one: Section headers were in bold when original template was used. I guess it's not really important but just to note...
I was looking at this
Code: Select all
{if isset($node->children)}<a href="{$node->children.0->url}">{$node->menutext}</a>
and this
Code: Select all
{include file=$smarty.template nodes=$node->children depth=$depth+1}
to see if I can figure out if there is something I could change to make it work but I got stuck again.

Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 11:06 am
by velden
I guess you're calling the {Navigator ...} with number_of_levels parameter?
So those children won't be available.
I think you should increase the number_of_levels with 1 and then do the check inside the template to not recurse when level is too deep.
Further, my code was just an example so I don't think the {include file=...} part will work. Better use the method used by default in this template.
Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 11:26 am
by jakovbak
If I increase depth by 1, section headers get their links but all children links become visible. With your template.
If I use original template there is no link on section header again. So, your example code is not quite useless after all...

Now I have to figure out how to hide children and that's it!
Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 11:54 am
by velden
It's a little ugly but functional:
Code: Select all
{if isset($node->children) && $depth < 2}
{Simplex_footer_menu data=$node->children depth=$depth+1}
{/if}
Use that in some places inside the template. I think it should be '< 2' but if it's not working try other numbers.
Re: [SOLVED] Adding link on section header in sitemap: How t
Posted: Thu Jun 08, 2017 1:01 pm
by jakovbak
I really can't figure out why you say it's ugly? Today, it could be the most beautiful thing I have seen!!! Because it works like a charm! I have change {if isset($node->children) && $depth < 2} to {if isset($node->children) && $depth < 1} but you did the hard part and I'm so grateful.
Thank you and have a great week!
Best regards,
Jakovbak
Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 1:36 pm
by velden
It's ugly because it's hard coded (the number).
But one could make it more flexible using the number_of_levels parameter variable in the template.
Good it works like you want it to.
Re: Adding link on section header in sitemap: How to?
Posted: Thu Jun 08, 2017 2:59 pm
by jakovbak
Oh well, hard coded number might be ugly in terms of flexibility. But smarty is unfortunately useless to most of us who are mostly design-oriented users. I always regret a lack of time for learning and getting a bit deeper into smarty because, as I can see (mostly from solutions you so generously provided!), it often takes only a few lines of code to make many things faster and easier.
Well, maybe one of this days...

Thanks again and best regards!