How do I add a custom string to symfony2 path? - twig

I have a custom page in /web/blog and I want to create a link to forward to it. How can I do this ? I have tried many things but none of them works, like
<a href="{{ path('homepage') | '/blog' }}" title="" >{{ 'menu.blog'|trans }}</a>
or
<a href="{{ path('homepage') }}/blog" title="" >{{ 'menu.blog'|trans }}</a>

I don't know why but the right answer is :
<a href="{{ path('homepage') }}{{ 'blog' }}">

i use
<a href="{{ path('homepage')}}/{{blog}} title="">
#Adam solution is right

Related

Remove tracking URL parameters from WordLift Faceted Search (Related Articles)

Can we remove the tracking urls parameters ?utm_source=wordlift&utm_medium=wl_faceted&utm_campaign=recommendations used in the related article section?
Yes, WordLift Faceted Search uses a Handlebars template.
The default template looks like this:
<script id="faceted-search-template" type="text/x-handlebars-template">
<aside class="wl-cloud-widget-wrapper wl-faceted-wrapper wordlift-cloud-widget wordlift-faceted">
<h3>{{title}}</h3>
<nav class="chips">
{{#each entities}}
<span class="chip {{activeClass}}" data-referenced-posts="{{referencedPosts}}"
data-id="{{id}}">{{label}}</span>
{{/each}}
</nav>
<section class="cards">
{{#each posts}}
<article class="card" data-post-id="{{ID}}">
<a href="{{permalink}}?utm_source=wordlift&utm_medium=wl_faceted&utm_campaign=recommendations">
{{#if thumbnail}}
<div class="thumbnail" style="background-image: url('{{thumbnail}}');"></div>
{{/if}}
<div class="card-content">
<header class="title">{{post_title}}</header>
</div>
</a>
</article>
{{/each}}
</section>
<nav class="nav-links">
<span class="nav-link previous">❮</span>
<span class="nav-link next">❯</span>
</nav>
</aside>
</script>
A developer can create a new template and embed it into the page, then set the template_id property of the wl_faceted shortcode to the id of the new template.

Excluding products from shopify search

I am trying to exclude certain products with a specific tag. I was able to exclude products using {% unless result.tags contains 'wholesale' %} on the search page, but having trouble with the search header. The template I have been modifying is using the raw tag. Anyone got any suggestions?
{% raw %}
{{#if has_results}}
<ul class="header-search__products grid">
{{#each results}}
<li class="grid__cell 1/3--handheld-and-up 1/4--desk">
<div class="product-item product-item--push">
{{#if on_sale}}
<div class="product-item__labels labels"><span class="label label--on-sale">{{#root.on_sale_label}}</span></div>
{{/if}}
<figure class="product-item__image-container">
<a href="{{url}}" class="product-item__link">
<img class="product-item__image " src="{{image}}" alt="{{image_alt}}">
</a>
</figure>
<div class="product-item__info">
<h3 class="product-item__title">
{{title}}
</h3>
{{#if on_sale#}}
<span class="product-item__price product-item__price--new" data-money-convertible>{{price}}</span>
<span class="product-item__price product-item__price--old" data-money-convertible>{{compare_at_price}}</span>
{{else}}
<span class="product-item__price product-item__price--new" data-money-convertible>{{price}}</span>
{{/if}}
</div>
</div>
</li>
{{/each}}
</ul>
{{results_label}}
{{else}}
<p class="header-search__no-results h4">{{results_label}}</p>
{{/if}}
{% endraw %}
Thankfully, it’s pretty easy to hide a product from your shop’s search. It involves adding some custom metadata.
This is the data you want to add:
"namespace" : "seo"
"key" : "hidden"
"value" : 1
"value_type" : "integer"

How can I get the value of an input in twig and reuse in an url that exists in the same page twig without the use jquery

<div class="product-btns">
<div class="qty-input">
<span class="text-uppercase">QTY: </span>
<input name="quantite" class="input" type="number">
</div>
{% if app.user != null %}
<a id="test" href="{{path('commande'{'id_product':listProduct.id ,'id_user':app.user.id,'quantite': })}}" class="primary-btn add-to-cart">
<i class="fa fa-shopping-cart"></i>
Add to Cart
</a>
{% else %}
I want to get value of input name="quantite" and reuse in path of parameter 'quantite'.
Have you tried ?
{{ form.vars.value.quantite }}

Pimcore with twig; render html based on menu depth

I'm using Pimcore 5.4.4 in combination with twig and I'm trying to customize my output. Currently I have this:
$this->setViewAutoRender($event->getRequest(), true, 'php');
$this->view->navigation=$navStartNode;
which I render with this:
{{ pimcore_render_nav(mainNavigation) }}
This does its job, it is however horribly uncustomizable.
I want to render an arrow-down icon for the menu Items that have children. Can this be achieved in any way?
To clarify, I would like my markup to look something like this:
<ul>
<li> m1 </li>
<li class='hasChildren'><i 'arrow-down'> m2 </i></li>
<ul>...
which should then display an arrow-icon next to the items which have children.
Any help here would be much appreciated.
Greetings, derelektrischemoench
Is it not possible to overwrite the partial?
See the documentation:
https://pimcore.com/docs/master/Development_Documentation/Documents/Navigation.html#page_Individual-Partial-Navigation-View-Script
Here's an entire custom navbar that works for me with Bootstrap 4.3.1 and mdbootstrap 4.8.9, tested with Pimcore 6.2.0:
<header>
{% set mainNavStartNode = document.getProperty('mainNavStartNode') %}
{% if mainNavStartNode is empty %}
{% set mainNavStartNode = pimcore_document(1) %}
{% endif %}
{% set mainNav = pimcore_build_nav(document, mainNavStartNode) %}
{% set renderer = pimcore_nav_renderer('menu') %}
<nav class="navbar navbar-expand-lg navbar-dark indigo mb-4">
<!-- Additional container -->
<div class="container">
<!-- Navbar brand -->
<a class="navbar-brand" href="{{ mainNavStartNode }}">
<img src="{{ asset('static/img/lovia-navbar-white.png') }}" alt="Lovia"
style="height: 1.3rem; margin-bottom: 0.4rem;">
{# <strong>Lovia</strong> #}
</a>
<!-- Collapse button -->
<button class="navbar-toggler" type="button"
data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="{{ "Toggle navigation"|trans }}">
<span class="navbar-toggler-icon"></span></button>
<!-- Collapsible content -->
<div class="navbar-collapse collapse" id="navbarSupportedContent">
<!-- Links -->
<ul class="navbar-nav mr-auto">
{% for page in mainNav %}
{% if page.isVisible() and renderer.accept(page) %}
{% if page.hasPages %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ page.label|trans }}</a>
<div class="dropdown-menu dropdown-primary" aria-labelledby="navbarDropdownMenuLink">
{% for child in page.pages %}
<a class="dropdown-item" href="{{ child.href }}">{{ child.label|trans }}</a>
{% endfor %}
</div>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{{ page.href }}">{{ page.label|trans }}</a>
</li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
<ul class="navbar-nav ml-auto">
{{ include('Includes/login.html.twig') }}
{{ include('Includes/language.html.twig') }}
</ul>
</div>
</nav>
</header>
Adapted from https://pimcore.com/docs/master/Development_Documentation/Documents/Navigation.html#page_Using-Partials-Generating-a-Customized-Navigation

How to display img inside twig with variable + string concatenate?

I have problem for displaying img, i saved images with name of book and now to access them need to concatenate .jpg extension. So my problem is how to concatenate variable and string inside twig template ?
<img src="{{ path({{ book.name ~ '.jpg' }}) }}"/>
here is full code:
{% for book in books %}
<a href="{{ path('AppBundle_Book_detailsBook', {'bookId': book.id}) }}"
class="col-2 white kartica">
<img src="{{ path({{ book.name }} ~ '.jpg' ) }}"/>
<h4>
{{ book.name }}
</h4>
</a>
{% else %}
No books.
{% endfor %}
Based on your comments, I think this is what you need:
<img src="{{ asset( '../app/Resources/images/covers/' ~ book.name ~ '.jpg') }}"/>
You might need to adjust the path slightly. Assets start from the web/ directory. I think you should get the idea.
By the way, thank you for making a detailed post!
Why don´t you try these:
<img src="{{ path( book.name ~ '.jpg' ) }}"/>

Resources