FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Help with layouts for article pages.

Feed 4 posts, 3 voices

Avatar
7 posts

Hi there,

On all my news articles I need to put a div around the content so that I can but a border round the content. However I don’t know of a way I can this in the layouts so that it doesn’t apply the same border to the articles page (the parent of the articles).

At the moment I have to set the layout to “article page” each time I create a new article.

Is there a way I can set an if statement in the layouts so it only applies it to article pages?

 
Avatar
184 posts

Hey,

What you want to do, is check for the slug value of the articles index (parent of the articles) in the layout. If it is true, don’t show your border, else, it is a article page so show your border.

Perhaps something like this before the article:

if($this->slug() != "articles")echo"<div class='border'>";

And don’t forgot to close the div after the article:

if($this->slug() != "articles")echo"</div>";
 
Avatar
1493 posts

I was thinking something a bit different from BlueFrog, since if you put that in your layout, it will show up on other pages than Articles, like your About page, and so on. Slight variation would be:

<?php echo ($this->parent->slug() == 'articles') ? '<div id="borders">' : ''; ?>

 ... page content ...

<?php echo ($this->parent->slug() == 'articles') ? '</div>' : ''; ?>

If you put that in your layout, it should give you your div ONLY on articles pages ever.

 
Avatar
184 posts

Ah, David makes a good point.
My suggestion relies on using a unique layout for the articles (parent and sub-pages).
Sorry for not making that clearer.

 
Avatar
7 posts

Hi guys,

Thanks for this advice. I’m loving the community here. I hope I can contribute and share my knowledge once I start getting more comfortable.