Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello,
I'm new working with Couch and i need a little advisory on my work.

A have created a news site with this structure: Blog (articles, pages with all articles of a certain category) and the homepage (index) where i want to post certain articles which already exists and have been created in blog.
For that i was thinking creating a dinamic input like checkbox, named "Featured" - for the article display on homepage. My problem seems to be the "if" condition.
Beacuse, it didn't worked with checkbox, i tried with "my_property_type", but couldn't make it work either.

This is what i had in mind:

On blog.php
<cms:editable name="my_property_type" label="Status articol" desc="Selecati una din valori"
opt_values='Featured | Common'
opt_selected = 'Common'
type='dropdown'
/>

On index.php - condition
<div class="article1">
<cms:if my_property_type='Featured' >
<cms:pages masterpage="blog.php" limit="1" folder='educatie' >
<h2><a hre="<cms:show k_page_link />"><cms:show k_page_title /></a></h2>
<div class="clr"></div>
<cms:show k_page_foldertitle /> - <cms:date k_page_date />
<img src="<cms:show blog_image />" alt="" width="195" height="132" />
<cms:excerptHTML count='55' ignore='img'><cms:show blog_content /></cms:excerptHTML>
<p><a href="<cms:show k_page_link />"> Read More...</a></p>
</cms:pages>
</cms:if>
</div>

Or for the checkbox case:
<div class="article1">
<cms:if "<cms:not_empty featured />" {where featured is the name of the input}
<cms:pages masterpage="blog.php" limit="1" folder='educatie' >
<h2><a hre="<cms:show k_page_link />"><cms:show k_page_title /></a></h2>
<div class="clr"></div>
<cms:show k_page_foldertitle /> - <cms:date k_page_date />
<img src="<cms:show blog_image />" alt="" width="195" height="132" />
<cms:excerptHTML count='55' ignore='img'><cms:show blog_content /></cms:excerptHTML>
<p><a href="<cms:show k_page_link />"> Read More...</a></p>
</cms:pages>
</cms:if>
</div>

I would really appreciate a little help!
THank you!
Hi and welcome @florentinachina

Your use of the if tag is outside of the pages tag. The variable my_property_type is not available in index.php; it is only available in blog.php itself or within a pages tag. The if condition therefore will always return false and nothing will be displayed. Nevertheless, even if we place the if tag inside of the pages tag, we encounter another problem. Since you have set limit to 1, the most recent article will be displayed and only if it is featured. If anything but the first article is featured, it will never be displayed. Let me know if this makes sense.

What you should do is remove the if tag and use the custom_field parameter of the pages tag:
Code: Select all
<div class="article1">
<cms:pages masterpage="blog.php" limit="1" folder='educatie' custom_field='my_property_type==Featured' >
<h2><a hre="<cms:show k_page_link />"><cms:show k_page_title /></a></h2>
<div class="clr"></div>
<cms:show k_page_foldertitle /> - <cms:date k_page_date />
<img src="<cms:show blog_image />" alt="" width="195" height="132" />
<cms:excerptHTML count='55' ignore='img'><cms:show blog_content /></cms:excerptHTML>
<p><a href="<cms:show k_page_link />"> Read More...</a></p>
</cms:pages>
</div>
http://www.couchcms.com/docs/tags-reference/pages.html
Thank you very much for your help!
You're also right with that limit condition, but since the "Featured" option works, i'll figure out a way to work, i raised the limit and it works for what i had in mind, but i'll think more on the posibilities.

I needed this quick and i couldn't pay that much attention to the documentation, so thank you very much!!! :D
3 posts Page 1 of 1