Simple question:
How do I set the ID for a selectize component?
I tried to do so in this bracket:
{{ember-selectize
id=name
selection=selection
content=attributes
optionValuePath="content.key"
optionLabelPath="content.value"
...
}}
But then the ID appears on the wrong level. Can anyone help?
Related
Shopware 6 | Cloning CmsElement and get null as data,
and in the Shopware 6 Forum: https://forum.shopware.com/discussion/67124/custom-product-box-no-data-in-the-storefront
I found this answer, but as I am still learning Shopware 6, I don't know if this is relevant for me. I have cloned the CMS Product Box Element, as I need to change the layout and add more flags/badges, but when I do a dump I get element.data = null. Would I also need to create a resolver too, or should I have just tried to extend the element with {% sw_extends '#Storefront/storefront/element/cms-element-product-box.html.twig' %}? But if I just extend I can't make the changes I want to the component.
Any suggestions or hints on how to solve the problem would be appreciated. Thanks.
I figured out it was much simpler than creating a new element. In the end, I found which components were being included and found that to change the layout and add a new badge I just needed to {% sw_extends '#Storefront/storefront/component/product/card/badges.html.twig' %} and for the parts of the product-box, just find the corresponding component and make the changes I needed to make in my plugin.
I'm new to Drupal & Twig and all I need is in my custom theme a twig expression to output the current user's ID. I can't find anything in the template comments, only if a user is logged in true / false.
Is there a simple way to get the ID of the current user? I'm not sure how to implement custom methods in a theme.
thanks!
Hello bobomoreno,
I would suggest you use the module Bamboo Twig.
The Bamboo Twig module provides some Twig extensions with some useful functions and filters aimed to improve the development experience.
You could then enable the sub-module Bamboo Twig - Loaders:
drush en bamboo_twig_loader -y
Finally, you will be able to use the Twig function bamboo_load_currentuser:
<!-- Get Current User -->
{% set user = bamboo_load_currentuser() %}
<div>{{ user.name.value }}</div>
<div>{{ user.uid.value }}</div>
You can find the complete official documentation there.
In your theme find file yourthemename.theme and add following code:
function yourthemename_preprocess(&$vars, $hook)
{
$vars['uid'] = \Drupal::currentUser()->id();
}
now if you edit your twig template for html, page, region, block, field, form element... you can use 'uid' token in your twig. It works for all hooks
If you only need the ID in user.html.twig, it's {{ user.id }}
Here's how D8 now works, in two lines of executable code:
<?php
// This code returns the current user ID.
$account = \Drupal::currentUser();
return $account->id();
The display name is not a field you can configure in {{ content }}. You can get it directly from the user entity:
{{ user.displayname }}
Reference for the php method: AccountInterface::getDisplayName
The Twig Tweak module is very small and yet very powerful. You can get the current user id with drupal_token('current-user:uid') I am using it to pass the current user id to a view like this:
{{ drupal_view('view_name', 'embed_1', drupal_token('current-user:uid')) }}
I contributed in back-office a select attribute with two options but when I'm doing
{{ ez_field_value(content, 'value') }}
I get 0 or 1 according to I contributed on back-office.
How to get value of this select attribute ?
I don't think there's a readily available way to get the clean value of the option from Twig.
What you can do though is use {{ ez_render_field(content, 'my_field') }} which will render the option name in a div element, but with added ezselection-field CSS class attached to it, like so:
<div class="ezselection-field">My option</div>
I'm currently on this feature, but a solution is far for me. I've tried many things, but i'm turning around my self.
Example: In the Content type "Entries" are more entries. I added a field with "type=select" and "values: entries/title".
How can i fetch the content from these "values" in the twig file?
Has anyone Ideas or Tipps?
you can use the following for the select field:
values: entries/id,title
So it saves the ID of the selected entry. Then in your template do the following to get the record:
{% setcontent selected_entry = 'entries/' ~ record.your_select_field %}
I read this from a recent answer to a question:
After enabling the extension, just use {{ twitterfeed() }} in your templates.
But, what if I only want say a contact form on one page? Putting the tag in the page's text field doesn't work. And putting it in the template would have it available on all the pages using that template. Do I have to duplicate a template to use only for the contact page? If not where do I put the contact form tag?
I went to Bolt's extension page, selected "how to use extensions" from the menu, and got this message:
No proper name for a page in the docs. Bye!
Perhaps someone at Bolt could fix the URL?
I would like to know why none of the extensions I want to use are not working. I am clearly missing a vital piece of info.
Thank you.
After enabling the extension, just use {{ twitterfeed() }} in your templates.
The Twig function {{ twitterfeed() }} belongs (generally speaking) in a Twig template file. You can use Twig in record fields, but that requires setting allowtwig: true for that Contenttype field.
But, what if I only want say a contact form on one page?
There are a few ways to do this, but the easiest way is to make a copy of your sites template file for the page's Contenttype and select that template for the 'Contact' record. The default 'pages' Contenttype that comes with Bolt has a templateselect field type that enables this.
No proper name for a page in the docs. Bye!
Fixed! Thanks for pointing it out.