Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [templating]

Front-end Twig templates that can Craftily render markup, scripts, and styles.

0
votes
0answers
3 views

Get Entry by Specific ID

I have a Freeform Email Notification getting sent out where I'm trying to fetch the ID of a specific entry that the Email is associated to. The emails are working, yet the entry that it's returning is ...
0
votes
0answers
9 views

Purge HTML but leave Line Breaks

I'm looking to purge all the html from a text field, but leave the line breaks in there. I currently have the following code, which makes line breaks happen, but unfortunately, people can add html to ...
0
votes
1answer
13 views

Two entries same category

I have two different sections that share the same category group that I want to display both on browser at the same time only if the category is the same. Doing that in Craft CMS is possible. Thank ...
0
votes
0answers
11 views

entry has only NULL fields

I am trying to upgrade from Craft CMS 2 to Craft CMS 3. So far, everything is working and the site is up and running, with the exception of one template. That template (see code below) uses the ...
1
vote
1answer
17 views

Get random entries from a section but keep the order of these when splitting the array

So I want to get 9 random entries from a section and I do this like so: {% set artists = craft.entries .section('artists') .artistImage(':notempty:') .with(['artistImage']) .orderBy('RAND()') ...
1
vote
1answer
16 views

How do you get the user id on the front-end?

I'm using Craft Pro to make a website where users have a private area. Users register and when login happens they are redirected to a page in the private area with respective info about that user. ...
1
vote
1answer
13 views

How to get an element query into json (for vue) without extra data?

Lets say I want to get a list of category names and ids and pass them into JSON (for vue.js). This is how I'm currently doing it: {% set sections = craft.categories.group('teamCategory').select(['...
1
vote
2answers
19 views

Searching a subset of fields

I have a section in Craft that has 36 fields, and I want to: set entries = craft.entries.section(sectionName).search(searchCriteria).all() where 'searchCriteria' searches only 6 of the 36 fields. ...
1
vote
1answer
22 views

Extend templates from outside templates directory

I have a setup where I'm using a component library that I have as an npm package. To use these components I need to extend templates that live outside of the /templates directory. So I need to achieve ...
2
votes
1answer
16 views

Maintaining order when getting by entries by ID

I'd like to get a certain set of entries in a specific order, but the element query comes back ordered by the default 'postDate desc' {% set ids = ['4213','3200','4204','4212'] %} {% set ...
1
vote
1answer
29 views

RequirePermission not working

I'm using the requirePermission tag in the templates for my Craft multisite. I only want users who have access to 'edit' that site be able to view it. My code is: {% requirePermission('editSite: (...
1
vote
1answer
20 views

Form Redirecting to Homepage

I'm trying to make a form redirect to the current page, but it's currently redirecting itself to the homepage every time the form submits? I can't see anything wrong with the code itself? <form ...
0
votes
1answer
17 views

Ajax Contact Form not sending with Error 400

Hi I have I'm using Craft CMS 3.1.21.1 with the Contact Form plugin version (2.2.4) and Contact Form Honeypot plugin (1.0.2) along with jquery 3.2.1 on the site. Whenever the form is filled out and I ...
1
vote
1answer
20 views

Entries with different styling

Is it possible to build categories with a list of entries that have different styling, like {% for entry in entries %} Row 1 - Entry 1 - full-wide Row 2 - 3 entries with (1/3 width of each) ...
1
vote
1answer
14 views

String interpolation in Redactor

I have a redactor field whose HTML contents contain links to other parts of the website. How do I render variables located in the HTML content of a Redactor field in Twig? Sample redactor content: &...
1
vote
2answers
68 views

Twig errors on v3.1.19

Running Craft 3.1.19 and have started getting twig error in the control panel. When I click on the utilities link I get this error: Declaration of craft\web\twig\Environment::compileSource(Twig\...
1
vote
1answer
43 views

Check if current page is the homepage

I'm trying to run a check within my _layout.html' to remove the navigation bar if the user is on the homepage. I've tried with the following code below, but browsing to a page which is theindex.html` ...
1
vote
1answer
21 views

How to add attributes to links/scripts?

How do I add additional attributes values while registering a CSS/JS file? I want to add a media attribute to one of the CSS links Example code: {% do view.registerCssFile(siteUrl ~ 'css/print.css',...
1
vote
1answer
13 views

Display Relating Entry based on Page Routing

I'm trying to create a submission page at the following URL structure /campaigns/this-is-a-test-creation/submissions As you can see /campaigns/ is the Channel and the /this-is-a-test-creation/ is ...
-1
votes
0answers
18 views

How to detect when a matrix block has not been created when embedded inside another matrix

I've a question.. how does one check if a embedded matrix has content ? I have a matrix field called listMatrix, inside I have a block listBlock another matrix with one block listItem containing ...
1
vote
1answer
47 views

Ignoring “The ” and “A ” when sorting entries

I have this code which used to work with 2.x versions: {% set foobars = craft.entries({ section: "foobars"}).order("(CASE WHEN title LIKE 'The %' THEN SUBSTRING(title, 5) WHEN title LIKE 'A %' THEN ...
1
vote
1answer
17 views

Output raw html from if statement and combining strings?

I have the following code: <img{{ block.imageWidth|length ? ' width="' ~ block.imageWidth ~ 'px"' }} /> If imageWidth is specified as 120, it should output: <img width="120px" /> ...
1
vote
1answer
23 views

Looping Related Entries with a Super Table

I need to loop related entries. I am using a SuperTable field with the handle "related" with an entry field with the handle "contentEntry" and two text fields for alternative text and descriptions. ...
1
vote
1answer
14 views

Display all fields without knowing object type?

I was looking for a way to show all fields/properties of a given object, and came across this useful tidbit: How to display all fields belonging to current entry? I'm new to Craft/Twig and didn't ...
3
votes
1answer
20 views

How to query entries written in a specific locale? (Craft 3)

In Craft 2 you used to be able to do something like {% set entries = craft.entries.section('something').locale('de') %} but .locale() has been removed and there's nothing similar in the docs that I ...
1
vote
3answers
31 views

404 – Not Found from _entry.twig templates in subdirectories

Following the Minjingo CraftQuest tutorial, I am getting an error on the front end when I access any routes other than the root/home page. In my template folder, I have a structure that looks like: ...
1
vote
1answer
45 views

How to strip out src=“” value with twig from iframe code

I have have a text field for copy-pasting an iFrame code. <iframe src="https://webpagelink.com/l/3556456/2019-03-06/34576" width="100%" height="500" type="text/html" frameborder="0" ...
1
vote
1answer
18 views

Grouping entries and ordering by section

Im grabbing entries from two sections and displaying them using the group filter. {% set entries = craft.entries().section('extendedEvents, festivalEvents')%} {% set allEvents = entries %} {% set ...
2
votes
1answer
31 views

How can I set an absolute image url for Open Graph Image tags?

I need the final tag to look like this: <meta property="og:image" content="http://mysite.com/uploads/resources/_hero/myimage.jpg"> If I use something like this: {% set seoImage = entry....
3
votes
1answer
44 views

Register JS files at the end of the body tag in the Control Panel

I would like to add my own external JS sources at the very end of the body tag in the Craft control panel. I've already tried using: {% do view.registerJsFile("<CDN_URL>", {position:3}) %} ...
1
vote
2answers
97 views

Search query for entries doesn't seem to work correctly

In my project I have a tickets which are edited in multiple steps where each step has it's own front end for. Now, of course. to continue editing an ticket I am required to fetch that exact ticket. ...
2
votes
1answer
23 views

How can I return only 1 random block in a Matrix in Craft using Twig?

I have a matrix with a couple of text fields for a caption, location and URL and an image Every time this page loads I want a random slide to show - so the background image is random, as well as the ...
1
vote
1answer
19 views

convert_encoding is screwing up Spanish-language characters

Standard "when article has no summary, output the first 200 characters of the body minus HTML" logic going on here. We're implementing some Spanish-language features for the first time and, while ...
1
vote
1answer
14 views

Set Property within Eager Loading

I'm looking to eager load and set another variable within the eager loading. But I can't seem to find out how on numerous guides/tutorials, and the query seems to be slowing the system down a bit. {...
1
vote
1answer
17 views

How do i get sites by group handle/name?

How can I get sites by their group handle/name within twig templates? Documentation only mentions querying sites by group id - getSitesByGroupId.
1
vote
0answers
16 views

A user cannot change the password without completing the profile

I have an issue. I have custom fields in the user profile, some of them are required. I also have a change your password page and a change your email password. A user can create an account (Without ...
1
vote
1answer
34 views

Templating repeatable blocks in a matrix field

I have a matrix field that has two different block types. The matrix field is on an entry that lists a number of benefits for a given product on a corporate website. The two different blocks are ...
1
vote
1answer
33 views

Fetching & Displaying an API Request using 'Fetch'

I'm currently in the process of calling an API endpoint and trying to display the data relating to it. But I'm having a bit of trouble using 'Guzzle/Fetch' in this scenario. I have the following code ...
1
vote
1answer
84 views

Give included twig component unique ID

When I include specific Twig template component multiple times, how can I give it a unique ID (or class)? Components are not inside for loop, so I cannot use loop.index. I also don't wont to pass ...
1
vote
1answer
9 views

Can I have non-boolean TargetBlank output using HTMLPurifier and the Redactor plugin?

I'm using the Redactor plugin throughout a Craft 3 site and I'm also using a custom HTML Purifier config to clean up the HTML (surprise). { "HTML.ForbiddenElements": ["&nbsp;", "br"], "...
1
vote
1answer
32 views

How can I load the templates from a module?

I'm creating a module that contains some predefined templates. How can I load them directly out of the vendor folder? I've tried doing Event::on(View::class, View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,...
1
vote
1answer
46 views

Solspace Freeform upload multiple image files

I've had a good look around and can't find any template reference to uploading multiple images with Freeform. In settings i've allowed for 5 files in 'File Count'. I'm using the following template ...
1
vote
0answers
28 views

How can I find out what type of entry is getting used?

I have an include that is being used for plain entries, and is also being used for categories. (Categories have their own urls) {% if entry is defined %} {% set entry = entry %} {% elseif ...
1
vote
1answer
36 views

What variables are available to redirectToPostedUrl?

Craft's Web Controller has a redirectToPostedUrl method. Copied here for the sake of discussion: public function redirectToPostedUrl($object = null, string $default = null): YiiResponse { $url = ...
1
vote
2answers
19 views

Merging Assets Fields

I've got this working but it seems terribly verbose to do something, that in my opinion should be easier. Is there a better way to get the assets from 2 different fields, merge them and output them ...
1
vote
2answers
23 views

Feed Me in Templates - can't pull in <itunes:summary>

I'm using Feedme to display content in my temmplates from a podcast RSS feed - not importing entries, just displaying. Everything is working fine except that I can't display the <itunes:summary>...
1
vote
2answers
57 views

Twig sometimes breaks JavaScript or CSS

Sometimes when your javascripts or stylesheets are formatted a certain way, twig seems to try and render those snippets (whom always include curly brackets in some way). For example, if you end you'...
1
vote
1answer
29 views

Trying to output contents of array

I'm trying to find a way of using php's print_r to output the entries that were pulled from the entries in the database. I'm pretty much brand new to Craft cms coming from Laravel, so a common thing I'...
1
vote
1answer
18 views

Craft 2 - Returning Value in Variable from Plugin to Template

I am working with a plugin and wish to return a value from it to the template that calls it. In my plugin, there is an XML feed call, and I would like to pass a value(variable) from the plugin to the ...
1
vote
2answers
35 views

Passing variables between sibling blocks

Is there any possibility to use "entry" from the for-loop inside the "main" block inside another block ("header" in my case)? See example below: {% extends "main" %} {% block header %} ...