1

This seems random to me, as it was not a problem until today...

I am getting the template error Variable "entry" does not exist with a reference to line06 below.

This is a template for social icons that I include on each page.

The code template below is included in my site template. It works on the index page, but it works no where else other than an actual entry (post) page.

<a href="https://twitter.com/intent/tweet?url={{ entry.url }}" class="social-link"> <i class="fa fa-twitter"></i> 
  • Would you mind cleaning up your code example a bit? This is pretty difficult to read. (ie: properly indent code, remove irrelevant tags) – Lindsey D Jan 27 '17 at 20:39
  • Does that work? – Hellyar Jan 27 '17 at 20:50
1

You can provide some fallbacks for pages that don't have en entry like this

{{entry.title|default('here is your fallback')}}

You can do this multiple times, chaining fallbacks. Inside the fallback you can provide a global or maybe set a page at the top of your template like this:

{% set entryFallback = craft.entries.id(1).first() %}
{{entryFallback.title}}

Edit

In your specific case where you just want to return the url from the page you are on to create a twitter share button, you can just get the current Url:

<a href="https://twitter.com/intent/tweet?url={{craft.request.url}}" class="social-link"> <i class="fa fa-twitter"></i> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.