0

I am trying to include a certain .html file if the URL has ?work=1.

So far I have this, which I got from Check URL for string in a Twig file.

 {% if 'work' in url %}
    {{ include('work/index.html') }}
 {% endif %}

They say I need a function in my .theme file to actually get the URL variable.
Is that right? Is there any way to get it with just Twig?

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • Have you inspected url to make sure it actually has the query string in it? There's a chance it won't, definitely worth checking. Re the variable existing or not - it completely depends what template it is and what vars it already has available. Sorry to be vague but it's hard to be more specific without more information about the problem – Clive Dec 16 '16 at 19:25
0

Ok nevermind. On the other stack I mentioned the function was

function riptide7_preprocess_page_title(&$variables) {
  $variables['url'] = $_SERVER['REQUEST_URI'];
  $variables['#cache']['contexts'][] = 'url.path';
    echo "What?!";
}

and I just had to change preprocess_page_title to preprocess_page

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.