<p>You can't automatically expand variables inside strings in Twig as you would normally do in PHP.</p>

<p>Instead, you have to concatenate your strings.</p>

<pre><code>{% set seo = craft.seo.custom('Discount codes and vouchers for ' ~ query, 'You searched for ' ~ query ~ '. Check out the latest live ' ~ query ~ ' discount codes &amp; voucher codes for ' ~ now|date('m') ~ ' ' ~ now|date('Y') ~ ' only at Vouchertoday.uk') %}
</code></pre>

CC BY-SA 3.0
2018-02-28T16:43:17.433Z
Thanks for the answer, but it seems to still not be setting the object?
JMKelley
CC BY-SA 3.0
2018-03-01T14:18:47.047Z
Try {% do craft.seo.custom(all the stuffs) %} instead of setting it to a local variable. NB: I haven't used this exact plugin myself, so I'm just trying to apply logic to it :)
Fuglsetrampen
CC BY-SA 3.0
2018-03-04T12:14:11.080Z
This throws an error.
JMKelley
CC BY-SA 3.0
2018-03-04T12:14:22.030Z
"Unexpected token "operator" of value "=" ("end of statement block" expected)."
JMKelley
CC BY-SA 3.0
2018-03-05T07:53:56.250Z
Hmm, could you post the entire line? There's no '=' in my example, so I need to see where else it could be going wrong
Fuglsetrampen
CC BY-SA 3.0
2018-02-19T09:02:16.907Z
2018-02-20T00:41:53.847Z
2018-02-20T00:41:53.847Z
Fuglsetrampen
<p>I'm currently using <a href="https://github.com/ethercreative/seo" rel="nofollow noreferrer">SEO by EtherCreative</a> on Craft 2, one of my pages needs a custom title and description injected into it like this on the docs:</p>

<blockquote>
  <p>In some cases, you will not have access to an SEO field, but will want
  to set the page title &amp; description. You can do this by creating a
  custom SEO object using the function below:</p>
</blockquote>

<pre><code>craft.seo.custom('The Page Title', 'The page description', $includeDefaultTitleSuffix)
</code></pre>

<p>Mine seems to be throwing errors or not doing anything like so:</p>

<pre><code>  {% set seo = craft.seo.custom('Discount codes and vouchers for {{ query }}', 'You searched for {{ query }}. Check out the latest live {{ query }} discount codes &amp; voucher codes for {{ "now"|date("m") }} {{ "now"|date("Y") }} only at Vouchertoday.uk') %}
</code></pre>

CC BY-SA 3.0
2018-02-17T13:19:19.437Z
Maybe you could explain the problem a little bit better? What doesn't work? What errors do you receive?
Robin Schambach
<plugins><seo><plugin-seo>
Setting a Plugin Object
# Setting a Plugin Object

(Asked by: username_0 on 2018-02-17)

I'm currently using SEO by EtherCreative on Craft 2, one of my pages needs a custom title and description injected into it like this on the docs:

In some cases, you will not have access to an SEO field, but will want
  to set the page title & description. You can do this by creating a
  custom SEO object using the function below:

craft.seo.custom('The Page Title', 'The page description', $includeDefaultTitleSuffix)

Mine seems to be throwing errors or not doing anything like so:
  {% set seo = craft.seo.custom('Discount codes and vouchers for {{ query }}', 'You searched for {{ query }}. Check out the latest live {{ query }} discount codes & voucher codes for {{ "now"|date("m") }} {{ "now"|date("Y") }} only at Vouchertoday.uk') %}

**Tags:** plugins, seo, plugin-seo
> **Comments:**
> **username_1**: Maybe you could explain the problem a little bit better? What doesn't work? What errors do you receive?  

---

## 1 answers

### Answer by username_2 on 2018-02-19. Score: 1

You can't automatically expand variables inside strings in Twig as you would normally do in PHP.
Instead, you have to concatenate your strings.
{% set seo = craft.seo.custom('Discount codes and vouchers for ' ~ query, 'You searched for ' ~ query ~ '. Check out the latest live ' ~ query ~ ' discount codes & voucher codes for ' ~ now|date('m') ~ ' ' ~ now|date('Y') ~ ' only at Vouchertoday.uk') %}

> **Comments:**
> **username_0**: Thanks for the answer, but it seems to still not be setting the object?  
> **username_2**: Try {% do craft.seo.custom(all the stuffs) %} instead of setting it to a local variable. NB: I haven't used this exact plugin myself, so I'm just trying to apply logic to it :)  
> **username_0**: This throws an error.  
> **username_0**: "Unexpected token "operator" of value "=" ("end of statement block" expected)."  
> **username_2**: Hmm, could you post the entire line? There's no '=' in my example, so I need to see where else it could be going wrong  

---

