How to include a piece of markup only on certain pages

Alan Wu asked on May 9, 2014 09:07

Hi There,

I am wondering if there's a way in the master template to have page detection macro, so that I can detect page and include markup only on certain page.

Thanks Alan

Correct Answer

Victor Hugo Garcia answered on May 9, 2014 09:39

yes, you can. Here a quick sample:

{% if (CurrentDocument.DocumentName.ToLower() == "home") {  %}
<link href="/CMSPages/GetResource.ashx?stylesheetname=Style" type="text/css" rel="stylesheet" />

I added that code under Header tab on my master template.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Alan Wu answered on May 9, 2014 09:44

Thanks! That works.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on May 19, 2014 04:03

There is another way to do this by including a webpart like HEAD HTML in this case to your master template, add the html to it and choose the document type you wish it to render on. e.g CMS.FAQ

The above technique is useful if you wish to add a particular markup on one and/or more than one page template. In case it's required only for a specific page template you can add this webpart directly under that page template.

Regards, Chetan

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.