Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
hi all,

i have footer.php template with repeatable menu

Code: Select all
        <cms:repeatable name='footer_menu_left' label='&nbsp;' group='kraujo_centras_block'>
            <cms:editable name='footer_menu_left_page_id' type='dropdown' label='Kairiniai meniu punktai' group='kraujo_centras_block'
            opt_values="<cms:nested_pages masterpage='top_menu.php' extended_info='0' include_custom_fields='1'><cms:show k_nestedpage_title />=<cms:show k_nestedpage_id /> | </cms:nested_pages>
                        <cms:nested_pages masterpage='main_menu.php' extended_info='0' include_custom_fields='1'><cms:show k_nestedpage_title />=<cms:show k_nestedpage_id /> | </cms:nested_pages>" />
        </cms:repeatable>



Image

all is great, when I debug via:
Code: Select all


<cms:pages masterpage='footer.php' extended_info='0' include_custom_fields='0'>
    <cms:show_repeatable "footer_menu_left">
        <cms:dump />
    </cms:show_repeatable>
</cms:pages>



i have debug info:
Image
all is great


but now i need to make a link to this page by this page id

how you can see, i have two nested pages menu templates: top_menu.php and main_menu.php

how to generate link?? like a

Code: Select all

<cms:pages masterpage='footer.php' extended_info='0' include_custom_fields='0'>
    <cms:show_repeatable "footer_menu_left">
        <cms link XXX="<cms:get 'footer_menu_left_page_id' />"/> <---- HOW TO GENERATE LINK BY NESTED_PAGE ID ???
    </cms:show_repeatable>
</cms:pages>


I need to get http://xxxx.ltd/top_menu.php?p=205 OR http://xxxx.ltd/main_menu.php?p=205
Hi,

Before I get to the finding the link part, please allow me to suggest a change to your code.
As it stands right now, the way your code is setting the 'opt_values' parameter of the dropdown potentially has a problem -
please see https://www.couchcms.com/forum/viewtopic.php?f=4&t=7045 for details.

To make the dropdown truly dynamic, please change the definition of your region to this -
Code: Select all
<cms:editable 
    name='footer_menu_left_page_id'
    type='dropdown'
    label='Kairiniai meniu punktai'
    opt_values="my_dynamic_params.html"
    dynamic='opt_values'
/>

and then create a snippet named "my_dynamic_params.html" (place it in your snippets folder) and place your code listing the nested-pages within it -
Code: Select all
<cms:nested_pages masterpage='top_menu.php' extended_info='0' include_custom_fields='1'><cms:show k_nestedpage_title />=<cms:show k_nestedpage_id /> | </cms:nested_pages> 
<cms:nested_pages masterpage='main_menu.php' extended_info='0' include_custom_fields='1'><cms:show k_nestedpage_title />=<cms:show k_nestedpage_id /> | </cms:nested_pages>

Ok, so now your dropdown will always reflect the current listing of your nested-pages.

Now, let us come to your original question.
We can simply use <cms:pages> to fetch the page we have the ID of and can get the link (or any other info) e.g. as follows -
Code: Select all
<cms:show_repeatable "footer_menu_left">
    <cms:if footer_menu_left_page_id >
        <cms:pages masterpage='top_menu.php' id=footer_menu_left_page_id limit='1'>
            <!-- all data about the page we had the ID of is here -->
            <a href="<cms:show k_page_link />"><cms:show k_page_title /></a>
        </cms:pages>
    </cms:if>
</cms:show_repeatable>

In your case there is slight hitch though because the page ID could belong to either of the two templates - 'top_menu.php' or 'main_menu.php'.
To handle that, we can first test the first template for the page and if the page is not found there we move to the second template. The code could now become as follows -
Code: Select all
<cms:show_repeatable "footer_menu_left">
    <cms:if footer_menu_left_page_id >
   
        <cms:set my_page_found='0' />
       
        <cms:pages masterpage='top_menu.php' id=footer_menu_left_page_id limit='1'>
            <a href="<cms:show k_page_link />"><cms:show k_page_title /></a>
            <cms:set my_page_found='1' />
        </cms:pages>
       
        <cms:if my_page_found='0' >
            <cms:pages masterpage='main_menu.php' id=footer_menu_left_page_id limit='1'>
                <a href="<cms:show k_page_link />"><cms:show k_page_title /></a>
            </cms:pages>
        </cms:if>
    </cms:if>
</cms:show_repeatable>

Hope it helps.
2 posts Page 1 of 1
cron