I have a view where there was a file type field. So I added it to the view and rewrote the result for it:
{{ title }}
The above line results in an a tag with the href for the PDF document and the node title as text for the tag.
Now I have replaced the field field_download with the field field_mdownload which is a reference to an entity of type Media document. I can't get the same result with this type of field.
I tried using Twig Twaek and Bamboo Twig for this purpose, and tried direct access to node and content too, but it doesn't seem to work in the context of the view.
I tried to use things like:
node.fileld_mdocument.entity.media_file_document.uri.value
node.field_mdocument | file_uri
field_mdocument | file_uri
file_url (field_mdocument)
<% set node = bamboo_load_entity ('node', nid)%> but here twig doesn't seem to be able to convert the nid to the entire value that represents the node. If I put <% set node = bamboo_load_entity ('node', 1)%> it works.
Does anyone have any idea how I can solve this?
Related
I've been struggling to show an existing content item to a another content item, what I can do as of now is just add the content part in a content item with using Flow and Bag, but the user really has to fill up the fields for these stuff. What I am trying to do here is for example make a styled 'button' (with the tags and such) with prefilled text in the button, then the user can edit it anytime within the content item it is called.
I am using orchard core with .net core 5.0
There are multiple ways to do this, the way I like to do it for styling is to make a content part with different fields, usually text fields and once the field is created, edit the field and change the editor type to predefined list, once this predefined list is created, one of them can be selected as default. Then add this content part as a part on the parent content type image of fields on contentpart image of predefined list
Another way would be to create a content picker field on an item, that's how you can include other content types on a parent item, I find this approach good for bigger content items (I.e. contentbanners etc) content banner content picker image
This approach is good but you have to use the contentitem filter (Liquid or razor) to get the content item as the parent content item only includes a reference to the content item and not the actual item.
{% for ContentItemId in Model.ContentItem.Content.ContentSections.Banners.ContentItemIds %}
{% assign contentSection = ContentItemId | content_item_id | shape_build_display: "Detail" %}
{{ contentSection | shape_render }}
{% endfor %}
The Third way, if you want content creators to add buttons etc in html editors etc would be via using shortcodes. shortcodes
I am working with Twig in Opencart 3.
If i have an HTML element
<span id='mobileCheck' style='display: none;'>mobile</span>
Is there any way to access either the id, or the content within Twig in order to use that in an if statement later?
In javascript i'd write
var isMobile = document.getElementById("mobileCheck").innerText;
Can i do something similar in Twig?
when i display ckeditor text the html tags are also displayed. how can a i show only the text? i'm getting this:
<b>Paragraph</b>
Paragraph
I use Jade template and node.
It's possible to delete Tag before save in database ? or remove tag after ?
Thanks.
I found a solution.
Juste use !{value} instead of #{value} with Jade template to decode html entities.
value contains html entities.
use unescape syntax in the pug file.
p
!= 'This code is <strong>not</strong> escaped!'
or
- var riskyBusiness = "<em>This code is <strong>not</strong> escaped!</em>";
.quote
p Joel: !{riskyBusiness}
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 am using Slim Framework and Twig.
I want to apply the DRY by using partials. I have a form that is reused in several views with different variables such as titles and route (url) names.
I am struggling on how to make it work on url names.
For example, there is this link using the ´urlFor´ helper with parameter as follows inside a view:
The link
So that is the link I want to pass to the partial template since, it is different in each view, I want to use the partial form. I have tried several approaches but it does not work. I don't know how to pass this string containing ' inside.
For example, I have tried this partial call inside the parent view like this:
{% include 'partials/partial.php' with {'theUrl': "urlFor('route.name', {parameter: value})"} %}
And inside the partial like this:
Show more
It does not work because in the browser's url I see the following:
http://myproject.dev/pages/urlFor('route.name',%20%7Bparameter:%201%7D)
It looks like it is not being escaped properly. Any ideas how to fix this when passing route names with urlFor()?
Without the greatest possibility for testing i think i found the problem. You are simply adding the function inside a string and that does not give the parser an oportunity to resolve the method, because it's basicly just a string.
{% include 'partials/partial.php' with {'theUrl': "urlFor('route.name',{parameter: value})"} %}
Should be
{% include 'partials/partial.php' with {'theUrl': urlFor('route.name',{parameter: value})} %}