Forum

Thread tagged as: Question, Blog

Blog - sectionSlug

How would i go about getting the section slug into a link in a blog template. My initial assumption was that I could use

<perch:blog id="sectionSlug" />

But sectionSlug doesn;'t seem to be exposed in that way.

Any thoughts?

Now Media

Now Media 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It should be - can you tell us more about the context?

The Blog on the site I am developing is in two sections - "news" and "blog" Each with their own pages at the URLs /news/ and /blog/ respectively.

This all works fine, apart from when you add archive/tag/category links into the sidebar, as my site makes use of a base tag. So these links goto archive.php?=xxxx relative to the root of the site. So I need to add the sectionSlug to the generated link so that it is /news/archive.php?=xxxx etc.

This is the code I am using for example in month_month_link.html template

<a href="/<perch:blog id="sectionSlug" />/archive.php?year=...

but this generates the link

<a href="//archive.php?year=....

not

<a href="/news/archive.php?year=

as expected.

Using Perch 2.4.9 (planning on upgrading to 2.5 today) PHP 5.4.14 MySQL 5.1.71-log Installed apps: content (2.4.9), perch_mailchimp (2.0.1), perch_blog (4.0.3)

I'll update to Perch 2.5 and Blog 4.1 respectively and see if that helps

All updated and still the same. Nice to see the Assets stuff though. This is going to be a brilliant addition :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which page functions are you using to output this template?

<?php perch_blog_categories(); ?>
<?php perch_blog_tags(); ?>
<?php perch_blog_date_archive_months(); ?>  
Drew McLellan

Drew McLellan 2638 points
Perch Support

Try this at the top of your page:

PerchSystem::set_var('sectionSlug', 'news');

Perfect. Thanks Drew :)

I may be back with more questions before this build is out ;)