Answers.Body: <p>If the string you're looking for is part of the URI segment, then something like:</p>
  
  <pre><code>{% if (craft.request.getSegment(3) == 'mySpecialKey') %}
      &lt;meta name="robots" content="noindex, follow"&gt;
  {% endif %}
  </code></pre>
  
  <p>(Adjusting the 3 for whichever part of the segment it's actually in.</p>
  
  <p>Or if it's part of the querystring, then use <code>craft.request.getParam('mySpecialKey')</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T09:02:44.500Z
Answers.Text: You could also compare against [`getPageNum`](http://buildwithcraft.com/docs/templating/craft.request#getPageNum) in the conditional: `{% if (craft.request.getPageNum() != 1) %}`.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T15:46:41.837Z
Answers.Text: Thanks, gents! The portion of the URL that I'd like to target is actually a ? as part of a query string. Essentially, I'd like the rule to be applied whenever a query string exists.The getSegment method above seems to work at targeting a portion of a static URL but is not working when I try to target the ? in the query string. Same for the getParam method. Is there a way that I can make a similar if / then rule based on whether or not a query string exists?
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T17:31:45.310Z
Answers.Text: Both `getParam('key')` and `getQuery('key')` should return from the querystring.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T21:58:31.590Z
Answers.Text: Thanks, Brad! I was able to get it working with your help.
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T00:53:35.043Z
Answers.LastActivityDate: 2015-05-29T00:53:35.043Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've got a website that has a resource center, news center and blog where each of those sections has a high quantity of assets that can be filtered by topic / type / date, etc. Additionally, due to the quantity of assets, we're using pagination to spread the assets across multiple pages.</p>
  
  <p>All of the filtering and pagination creates a variety of worthless but currently crawlable URLs that we'd like to hide from the search engines.</p>
  
  <p>I'm attempting to deploy the meta name="robots" content="noindex, follow" tag to all of the paginated / filtered URLs while keeping the overview pages indexed. It seems that the most logical way to do that is based on a consistent URL string that appears in both pagination and filtering instances.</p>
  
  <p>How can I add a rule within my template that will insert the meta tag based on whether or not a string exists in the current URL appearing in a user's browser?</p>
  
  <p>Any help would be much appreciated. Thanks!</p>
  
Tags: <templating><pagination><seo>
Title: If URL Contains x Then Do Y in Twig / Craft Template?
ThreadText: # If URL Contains x Then Do Y in Twig / Craft Template?
  
  (Asked by: username_0 on 2015-05-29)
  
  I've got a website that has a resource center, news center and blog where each of those sections has a high quantity of assets that can be filtered by topic / type / date, etc. Additionally, due to the quantity of assets, we're using pagination to spread the assets across multiple pages.
  
  All of the filtering and pagination creates a variety of worthless but currently crawlable URLs that we'd like to hide from the search engines.
  
  I'm attempting to deploy the meta name="robots" content="noindex, follow" tag to all of the paginated / filtered URLs while keeping the overview pages indexed. It seems that the most logical way to do that is based on a consistent URL string that appears in both pagination and filtering instances.
  
  How can I add a rule within my template that will insert the meta tag based on whether or not a string exists in the current URL appearing in a user's browser?
  
  Any help would be much appreciated. Thanks!
  
  **Tags:** templating, pagination, seo
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-29. Score: 3 | Accepted answer
  
  If the string you're looking for is part of the URI segment, then something like:
  
  ```
  {% if (craft.request.getSegment(3) == 'mySpecialKey') %}
      <meta name="robots" content="noindex, follow">
  {% endif %}
  
  ```
  
  (Adjusting the 3 for whichever part of the segment it's actually in.
  
  Or if it's part of the querystring, then use `craft.request.getParam('mySpecialKey')`.
  
  > **Comments:**
  > **username_2**: You could also compare against [`getPageNum`](http://buildwithcraft.com/docs/templating/craft.request#getPageNum) in the conditional: `{% if (craft.request.getPageNum() != 1) %}`.  
  > **username_0**: Thanks, gents! The portion of the URL that I'd like to target is actually a ? as part of a query string. Essentially, I'd like the rule to be applied whenever a query string exists.The getSegment method above seems to work at targeting a portion of a static URL but is not working when I try to target the ? in the query string. Same for the getParam method. Is there a way that I can make a similar if / then rule based on whether or not a query string exists?  
  > **username_1**: Both `getParam('key')` and `getQuery('key')` should return from the querystring.  
  > **username_0**: Thanks, username_1! I was able to get it working with your help.  
  
  ---
  
  