0

I am trying to add a p tag to the footer if the page is the home page, I am using spicycp, which uses .twig files.

I have tried a number of php if statements, but alas, to no avail:

 <p class="kktag">Digital Marketing by <a href="http://kingkong.com.au/" target="_blank">King Kong</a>
</p>
{% endif %} 
</p>   

and

$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'https://lfsigns.com.au/') 
{
   <p class="kktag">Digital Marketing by <a href="http://kingkong.com.au/" target="_blank">King Kong</a>
</p>
}
else
{
   <p class="kktag">Digital Marketing by King Kong</p>
}

and

{% if is_front %}
  <p class="kktag">Digital Marketing by <a href="http://kingkong.com.au/" target="_blank">King Kong1</a> </p>
{% endif %} 

and

{% if entry.id == 4 %}
<p class="kktag">Digital Marketing by <a href="http://kingkong.com.au/" target="_blank">King Kong</a>
</p>
{% endif %} 
</p> 

and

{% if template == 'index' %}
<p class="kktag">Digital Marketing by <a href="http://kingkong.com.au/" target="_blank">King Kong</a>
</p>
 {% endif %}

and

{% if is_front_page %} 
   <p> do something </p> 
{% else %} 
   <p> do something else. </p>
{% endif %}

But none of these seem to work, any ideas/suggestions/advice would very much appreciated,

Thanks everyone

Khadesa
  • 91
  • 3
  • 11
  • Found a [related answer](http://stackoverflow.com/questions/9339370/twig-templates-engine-get-current-url) for passing the `$_SERVER` super global array to Twig. Also, check out [Twig's docs](http://twig.sensiolabs.org/doc/templates.html#variables) for more info re: embedding variables in your template. – rhinosforhire Nov 11 '16 at 22:54

1 Answers1

0

You can get the current URL from the Request object. More details (Symfony docs).

{% if app.request.uri == 'https://lfsigns.com.au/' %}
    <p class="kktag">Digital Marketing by <a href="http://kingkong.com.au/" target="_blank">King Kong1</a> </p>
{% endif %}
rhinosforhire
  • 1,305
  • 11
  • 20
  • Thank for your help Rhono (coolest name i've read on stack in a long time) However, the condition is never true, i have modified the code to `{% if app.request.uri == 'lfsigns.com.au/' %}

    Digital Marketing by King Kong

    {% else %}

    Digital Marketing by King Kong

    {% endif %}` And the else statement is always true. I have tried different variations of the address, lfsigns.com.au, https://lfsigns.com.au/, /, but no such luck, Any ideas? Thanks Rhonos!
    – Khadesa Nov 09 '16 at 00:49
  • @Khadesa, Ah, sorry I left off the front. By the by, you can test what `app.request.uri` contains using `{{ app.request.uri }}`. In any case, I've updated my answer and thanks :) – rhinosforhire Nov 09 '16 at 02:55
  • Hi Rhono, Thanks again for your help, but i'm afraid it still doesn't become 'true', When you say `{{ app.request.uri }}`, do you mean i can print that in firebug console, which would allow me to see the correct url? How might i print this? Thanks again man :] – Khadesa Nov 09 '16 at 06:32
  • I just realized your question isn't tagged Symfony. Please disregard my answer. – rhinosforhire Nov 09 '16 at 06:52