Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi,

Instead of k_page_title in Mosaic, I get a file number

Like that:
Code: Select all
<div class="bandeau"><amp-img src="<cms:show bandeau />" alt="<cms:show k_page_title />" width="<cms:show bandeauw />" height="<cms:show bandeauh />" layout="responsive" /></div>


Where alt="<cms:show k_page_title />" gives : alt="1411951c15022e75b78587f3f03bac5e"

Example at: https://www.pauloeuvreart.com/difference-entre-impression-sur-toile-et-peinture-sur-toile.html

Did I miss something?? :mrgreen:

Thanks for any advice,
Paolo
Paolo,

Welcome to the game of scope. Different depths, different currents :)

To start with something, let me remind - Mosaic Tiles are represented internally as hidden clonable templates. Instances of Tiles are cloned pages of such templates. Each tile therefore has all variables (including, of course, k_page_title) of that tile's internal cloned page.

Next, Couch has 3 scopes to set/put variables in - global, parent, local and 2 scopes to show/get variables from - global, local.

To get 'k_page_title' from the visited page, while being deep inside nested tags, one must find it in the desired scope.
Let me share with you my cheatsheet to illustrate scopes applied to Mosaic.

Code: Select all
<cms:if k_is_page>
    <cms:nl2br>
    Test1. <hr>
    Visiting a page <cms:show k_page_id />

    <cms:show_mosaic 'content' limit='1' tiles='text'>

        <cms:show k_page_id /> - page_id from mosaic

        <cms:show k_page_id scope='global'/> - global scope, page_id from template via cms:show

        <cms:get 'k_page_id' scope='global'/> - global scope, page_id from template via cms:get

        <cms:show k_page_id scope='local' /> - local scope, page_id from mosaic

    </cms:show_mosaic>

    Test2. <hr>
    Visiting a page <cms:show k_page_id />

    <cms:pages show_unpublished='1' id="NOT <cms:show k_page_id />" limit='1'>

        Requesting a page-view context of another page <cms:show k_page_id />

        <cms:set my_context_page_id_parent = k_page_id scope='parent' />
        <cms:set my_context_page_id_local = k_page_id scope='local' />
        <cms:set my_context_page_id_global = k_page_id scope='global' />

        <cms:show_mosaic 'content' limit='1' tiles='text'>

            <cms:show k_page_id /> - page_id from mosaic

            <cms:show k_page_id scope='global'/> - global scope, page_id from template via cms:show

            <cms:get 'k_page_id' scope='global'/> - global scope, page_id from template via cms:get

            <cms:show k_page_id scope='local' /> - local scope, page_id from mosaic



            <cms:show my_context_page_id_parent /> - my_context_page_id_parent - no scope
            <cms:show my_context_page_id_parent scope='global' /> - my_context_page_id_parent - global scope    (will not be found)
            <cms:show my_context_page_id_parent scope='local' /> - my_context_page_id_parent - local scope  (will not be found)

            <cms:show my_context_page_id_local /> - my_context_page_id_local - no scope
            <cms:show my_context_page_id_local scope='global' /> - my_context_page_id_local - global scope  (will not be found)
            <cms:show my_context_page_id_local scope='local' /> - my_context_page_id_local - local scope    (will not be found)

            <cms:show my_context_page_id_global /> - my_context_page_id_global - no scope
            <cms:show my_context_page_id_global scope='global' /> - my_context_page_id_global - global scope
            <cms:show my_context_page_id_global scope='local' /> - my_context_page_id_global - local scope  (will not be found)

        </cms:show_mosaic>

    </cms:pages>
    </cms:nl2br>
</cms:if>


Please try yourself to understand which scope becomes parent/local to which tag. Global scope is, no doubt, the only one and is not complciated.

You can see that I included an example with a setted variable inside cms:pages scope and various outcomes of such action.
I know that getting/showing a variable with scope='immediate_parent' would likely be intuitive, but we don't have it in Couch yet and must buffer a variable unders another name to avoid it being lost in outer context.
Thanks a lot Trendoman, I didn't even know that it was existing.

scope='global' did the trick...

Have a wonderful day,
Paolo
I found it!! A great example of scope='parent' thoroughly explained by @KK viewtopic.php?f=2&t=11379#p30090

A Must-read for a long-time developer on CouchCMS. :)
4 posts Page 1 of 1