Page 1 of 1
Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 12:36 pm
by naturelab
I am trying to use either method below to get the Gallery assigned to a particular page.
Code: Select all
{page_attr page=$child.alias key="Gallery" assign='projectgallery'}
or
Code: Select all
{$projectgalleryf=cgsimple::get_page_content($child.alias,'Gallery')}
If the page type is 'content' this works fine, I use this all the time. However, if the page type is 'Internal Page Link' it doesn't seem to work.
How do I access the
page specified in the Internal Page Link, ie: the
destination link.
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 12:41 pm
by naturelab
Also, how do I check the content type of the page ? :-
Something like...
Code: Select all
{if content-type == 'inernallink'}Do something{/if}
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 4:54 pm
by Jo Morg
As for your 1st question: Internal links don't have a content, however they do have a property that you may access (although undocumented...) so you should be able to do something like this:
Code: Select all
{page_attr page={page_attr page=$child.alias key='page'} key='_dflt_' assign=projectgallery}{eval var=$projectgallery}
However you'd need to make sure that "$child.alias" is an internal link...
As for your 2nd question:
Code: Select all
{if $content_obj->Type() == 'pagelink'}Do something{/if}
The code may need a few tweaks to adapt to your use but the concept does work - I have tested it.
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 5:20 pm
by naturelab
Thanks Jo ! We love the undocumented properties !
So I am looping through a the child pages of a top level section, tryng to get the gallery from each ( some of the children are content pages, some are internal links.
Does this look right ?
Code: Select all
<!-- Display ALL children ( some are Internal Links ) -->
{$children=cgsimple::get_children()}
{foreach from=$children item='child'}
{$parenttitle=cgsimple::get_root_alias($child.alias)}
{$projecttitle=cgsimple::get_page_title($child.alias)}
{page_attr page=$child.alias key="Gallery" assign='projectgallery'}
{page_attr page={page_attr page=$child.alias key='page'} key='_dflt_' assign=internallinkprojectgallery}
<div class="element-item col-xs-6 col-sm-3 col-lg-3">
<h4 class="summary"><a href="{root_url}/{$parenttitle}/{$child.alias}/" title="{$projecttitle|escape:html}">{$projecttitle}</a></h4>
{Gallery dir={if $content_obj->Type( $child.alias) == 'pagelink'}internallinkprojectgallery{else}$projectgallery{/if} number="1" template="gallery_small" }
{/if}
</div>
{/foreach}
This bit doesn't seem to work. What am I doing wrong ?
Code: Select all
{if $content_obj->Type( $child.alias) == 'pagelink'}I am internal{/if}
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 5:33 pm
by Jo Morg
naturelab wrote:This bit doesn't seem to work. What am I doing wrong ?
Code: Select all
{if $content_obj->Type( $child.alias) == 'pagelink'}I am internal{/if}
Nope that won't work: {$content_obj} always refers to the current page content object. For the use you are after, and since you have CGSimpleSmarty you should be able to use:
Code: Select all
{if cgsimple::get_page_type($child.alias) == 'pagelink'}I am internal{/if}
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 5:43 pm
by naturelab
Thanks again. Nearly there, but not quite... updated code :-
Code: Select all
<!-- Display ALL children ( some are Internal Links ) -->
{$children=cgsimple::get_children()}
{foreach from=$children item='child'}
{$parenttitle=cgsimple::get_root_alias($child.alias)}
{$projecttitle=cgsimple::get_page_title($child.alias)}
{if cgsimple::get_page_type($child.alias) == 'pagelink'}
{page_attr page={page_attr page=$child.alias key='page'} key='_dflt_' assign=projectgallery}{eval var=$projectgallery}
{else}
{page_attr page=$child.alias key="Gallery" assign='projectgallery'}
{/if}
<div class="element-item col-xs-6 col-sm-3 col-lg-3">
<h4 class="summary"><a href="{root_url}/{$parenttitle}/{$child.alias}/" title="{$projecttitle|escape:html}">{$projecttitle}</a></h4>
{Gallery dir=$projectgallery number="1" template="gallery_small" }
{/if}
</div>
{/foreach}
This bit in bold doesn't seem to work (yet)
Code: Select all
{page_attr page={page_attr page=$child.alias key='page'} key='_dflt_' assign=projectgallery}{eval var=$projectgallery}
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 5:54 pm
by naturelab
Works now ! Thanks
Code: Select all
{page_attr page={page_attr page=$child.alias key='page'} key='Gallery' assign=projectgallery}{eval var=$projectgallery}
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 5:59 pm
by Jo Morg
Yup, key='Gallery'... I had no way to know it that was a valid content block or not... _dflt_ is the default content...
Glad I could help.
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 6:01 pm
by naturelab
Cheers Jo ! Sounds dumb, but how do I mark this thread as [solved] ? I can never figure it out !
Re: Internal Page Link > Access specific content blocks
Posted: Mon Nov 28, 2016 6:02 pm
by Jo Morg
Just click the green tick of the post that offered the correct answer (or any other for that matter)

.