Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hi everyone!
I have done some templates for linguistic theory for different languages on my website. All is managed by CouchCMS.
Now I have to do a "study plan": every "day" in a study plan is a cloned page, and every "day" you have some theory to learn.
The administrator is supposed to enter couchCMS-managed URLs into array of textareas, represented as <cms:repeatable>.
Code: Select all
<cms:template clonable='1' nested_pages='1' order='1' title="<?= $template_title ?>">
   <cms:repeatable
      name='links'
      order='1'>
      <cms:editable
         name='url'
         type='textarea'
         label='URL'
         width='590'
         height='50'
         col_width='500'
         no_xss_check='1' />
   </cms:repeatable>
</cms:template>

Now when the user visits a page, corresponding to a "day" in the study plan, he or she has to see chunks of text from those links (at least page titles).
I've tried using <cms:php> tag, but it doesn't work as expected:
Code: Select all
<cms:show_repeatable 'links'>
   <cms:php>
   $url = '<cms:show url />';
   if (strpos($url, 'http://')===0) {
      if(strpos($url, 'theory')!==FALSE) {
         $split_url = explode('/', $url);
         $page_name = $split_url[count($split_url)-1];
         echo sprintf('<cms:pages masterpage="/theory/german.php" page_name="%s">test<cms:show k_page_title /></cms:pages>', $page_name);
            }
}
           </cms:php>
</cms:repeatable>


When I try not using sprintf and place page_name manually instead of %s, it does work.
My suspicion is that I cannot use <cms:pages> with dynamic parameters inside of <cms:php> tag. Is this true? If so, how would you overcome this limitation?

Many thanks for any help.

Best regards,
Helga.
OK, I've completely forgot about <cms:set> tag. Here is the solution:
Code: Select all
<cms:show_repeatable 'links'>
<cms:set theory_page_name="<cms:php>
   $url = '<cms:show url />';
   if (strpos($url, 'http://')===0) {
      if(strpos($url, 'theory')!==FALSE) {
         $split_url = explode('/', $url);
         $page_name = $split_url[count($split_url)-1];
        echo $page_name;
</cms:php>" />
<cms:pages masterpage="/theory/german.php" page_name="<cms:show theory_page_name />">
    <cms:show k_page_title />
</cms:pages>
</cms:repeatable>
Hi :)

Allow me to explain a bit as to why your first attempt was not working as you expected.

The cms:php tag first executes all its child tags to get their final output (hopefully valid PHP code) that it moves on to try and execute as PHP.

So, for example, the following code -
Code: Select all
<cms:php>
   echo sprintf('<cms:pages masterpage="/theory/german.php" page_name="%s">test<cms:show k_page_title /></cms:pages>', $page_name);
</cms:php>

- would actually evaluate to this PHP code that will be executed
Code: Select all
   echo sprintf('', $page_name);

As you can see, the cms:pages would have already executed (and wouldn't have outputted anything as there would be no page with a literal name of '%s').

Hope this helps.
3 posts Page 1 of 1