Display JavaScript only on the homepage What is the best method to render Javascript on specific page using name instead of id. This is what I found but not sure how to use name instead. 

{% if entry.id == 2 %}
{% endif %}

{% if entry.section == homepage %}
    //Content goes here
{% endif %}
You'd typically use the {% includeJs %} or {% includeJsFile %} tags within your page template, to specify your page-specific JavaScript, and then output everything in your layout template by calling {{ getFootHtml() }}.

Here's how your (very basic) page template might look in practice:

{# mypage.twig #}
{% extends '_layout' %}
{% includeJsFile "/assets/js/mypage.js" %}


And here's how your (equally basic) layout template might look:

{# _layout.twig #}
&lt;!doctype html&gt;
&lt;html&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;

{# This outputs the JavaScript from mypage.twig #}
{{ getFootHtml() }}
&lt;/body&gt;
&lt;/html&gt;