Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
12 views

Stuck when grouping entries to get any other parameters like url, id etc

So I am trying to group entries by location and then group entries in this group by weekday. I have this aspect working with the following code: {% set allClasses = craft.entries .section('...
1
vote
1answer
23 views

Problem with Twig group function, group by year

I am trying to apply the group filter so that my year headings appear in DESC order. They are appearing in ASC order instead, and applying |reverse doesn't work. Suggestions? {% set entries = craft....
1
vote
1answer
25 views

Add variable to twig context

I have created an event to transform the entry data before rendering the page so that it's ready to render components in the template. Event::on(View::class, View::EVENT_BEGIN_PAGE, [$this, '...
1
vote
2answers
43 views

How do you modify the entry data before the template is rendered?

I am using a pattern library which expects a different data structure to what is in entry. Is there a way to parse the entry through a transformer class before the template is rendered? Currently I ...
1
vote
1answer
32 views

How to get the previous or next two entries with images and

To expand upon How to get the previous or next two entries I was wondering how I can also add the image and an input from each entry. I have simplified the html-structure in this example but ...
1
vote
1answer
32 views

Homepage template / queries

I might be over-engineering this a bit, but I'm looking for a clean way to set up my homepage, for as few database queries and maintaining a DRY setup. The homepage is: Hero introduction Fields in a ...
1
vote
1answer
20 views

Get all orders which contains a certain product type

In want to print a list of orders: {% set orders = craft.orders.completed(true).limit(null).all() %} Now I want to make a list of orders with only the product.type XYZ. I tried to fabricate ...
0
votes
0answers
50 views

Overwrite template-files

I want to use one template on several Craft websites (different installations, not multi-sites). Is there a way in Craft I can do something like this? I want to update/overwrite the /templates/core/ ...
1
vote
1answer
21 views

link twig template in a tag

I created two twig templates: home.twig and about.twig. in home.twig it's this code: <a href="/about">go to about template</a> and in about.twig it's: <h1>about</h1> when I ...
1
vote
1answer
18 views

Templating data in HTML

I have an Matrix field and I want to extract data in the following HTML structure: <div class="row"> <div><p>text1</p><img src="{{imgurl1}}" /></div> <div&...
1
vote
1answer
8 views

How to build a language switcher that covers entries with custom routes?

I have a site with a structure and various channels, that live inside that structure. I started with the language switcher from https://craftcms.stackexchange.com/a/26347/8325; but that will only ...
0
votes
0answers
8 views

Cached Images falling back to IP

I'm having a strange problem which I'm unsure if it's my hosting or my Craft's config. My images which I have within a Cached template, once the cache expires or sometimes before they go back to the ...
1
vote
2answers
46 views

Correct Limit for Entries with IF statements

I have content on my site that can't be shown in some countries and requires a basic level of geo-targeting, based on the users profile and not by any form of IP geo-targeting. I have set up an ...
1
vote
1answer
20 views

Pushing additional key values without overwriting existing key values in an array

For an existing key in an associative array, I'm trying to push a new value to it without overwriting the existing values in the key. I've tried this: {% set myArray = { myKey: [ 'value1',...
0
votes
0answers
10 views

Craft CMS 2.9.2 template issue

My script looks like <div class="xl-left"> <h5>Rock</h5> <ul class="list-reset filters__list" data-filter-group="type"> {% for category in craft.categories....
2
votes
2answers
49 views

How to get second last url segment

I'm setting up a dynamic thank-you page for all forms added to the site. Client can add forms with freeform to any page and I have set the return url to this: {{ form.renderTag({ class: "w-full ...
1
vote
1answer
30 views

Output Relative URL

I need to output the relative URL for the current page for a GA event label. According to Craft 3 docs, it seems like rootRelativeUrl() as in: {% relative = entry.rootRelativeUrl() %} should do ...
1
vote
1answer
23 views

How to display plain text only from redactor without any line break or format

Is there a way to display plain text only without any line break or format style. I have an input field using the redactor. I want the result to shows plain text without any formatting for this ...
1
vote
1answer
23 views

Trouble finding the correct path to template in custom module and getting the “Unable to find the template” error

I've created a custom module trying to implement new field types. I'm using How to create custom field type in Craft 3 and https://github.com/mmikkel/IncognitoField-Craft3 as reference on how to ...
1
vote
2answers
33 views

Need help with a Twig template error

I am getting the following Twig error and I cannot figure out what is wrong. I'm new to Twig. Twig Syntax Error – Twig\Error\SyntaxError Unexpected "minify" tag (expecting closing tag for the "cache"...
1
vote
1answer
35 views

Impossible to access an attribute on a null variable - on the one() method - all() works!

First question - but I think this is a bug (not my fault). I have entries/pages (a structure) - one parent (product overview) with children (products) I have one category group with categories - ...
1
vote
1answer
33 views

How to loop through a table and set variables based on the existence (or not) of data in those tables?

I am using a table field in Craft (price) limited to one row only, used to manage price setting in different currencies on an entry. The three cols each contain number fields with the handles dkk, ...
0
votes
1answer
33 views

Encoding special characters even with the raw filter due to include

Hey guys i have something odd happening and I don't understand why: The opening of my template i set a variable {% set text = component.textarea ?? null %} Lower in my template i have the following: ...
1
vote
1answer
28 views

Splitting a Twig Variable into 2 Variables

I want to split my variable into two new variables before and after the dash character "-". How do I adjust my code below to enable this to happen? {% set name = 'first-last' %} {% set firstNameSlug ...
1
vote
1answer
23 views

Slow Category Loading

I have the following category https://www.ticketstoday.co.uk/theatre which has around 600/700 Entries, this is paginated at 30x Entries a page. Unfortunately, it's loading rather slowly. It's not a ...
1
vote
1answer
40 views

Use Craft globals for CSS styles

Is it possible to pass a value from Craft global setting into a CSS/SCSS file? So for example I want to be able to allow the end user to customise colours and fonts without having to include it inline....
1
vote
1answer
30 views

Empty Date Field

I currently have an empty date field, it's unset in the field. I know from reading this becomes "Today's Date" but for some reason the following code is just not working when testing for empty? Unsure ...
1
vote
1answer
16 views

Multiple Asset Field Query

I'm looking to see if there's a better way of querying multiple asset fields in one query, surely there is but I just can't seem to find it in the docs. {% for asset in entry.eventMediaTile....
1
vote
1answer
20 views

Get Random Set of Entries

I'm trying to create a "Hack Job" version of Similar Entries, I'm using the following code but it seems to be getting the same entries over and over again. I know shuffle function does this, but I ...
1
vote
2answers
42 views

List authors on front end by total number of entries

I need to output a list of channel authors. There are about 40 authors but I want the 8 authors with the most entries. Not sure how to achieve this. What I have so far: {# get all the itbuzz ...
1
vote
1answer
29 views

Least CPU intensive way to get number of matching elements?

Which is the least CPU intensive (SQL-intensive) way to get the sum of products that are relatedTo a category? Like this? {% set productCount = craft.products.relatedTo(category)|length %}
0
votes
0answers
32 views

Intermittent internal server error

I'm experiencing a very intermittent internal server error on a Craft site running 3.3.7. The message "An internal server error occurred" appears every now and then when trying to load a page. The ...
0
votes
0answers
19 views

get pageTrigger in URL before pagination starts

When using pagination in TWIG / Craft, URLs will automatically add the pageTrigger to overview URLs. e.g. | <--- Entry URL ---> | <- pageTrigger -> | https://mydomain.com/news/...
0
votes
0answers
14 views

Use imported macro in another macrofile

We want to import a macro from one file in another one: test.twig {% macro testMacro() %} {# content of macro #} {% endmacro %} other_macros.twig {% from '_partials/macros/test.twig' import ...
0
votes
1answer
41 views

How to override UserController.actionLogin or the login form template in Craft 3?

Hi I'm trying to build a custom authentication plugin for an organization, and I'm having a hard time figuring out how to override the craft\controllers\UserController.actionLogin method. I tried ...
1
vote
1answer
27 views

How to duplicate entries and loop them without getting a Twig or deprecation error?

I'm trying to duplicate entries inside a macro, which will displays duplicated items inside a carousel. It's not possible to merge Element Queries. Even if it's possible to merge IDs, merging an ...
1
vote
1answer
17 views

Formatting Issues

I need help formatting my pages. Right now the way my CMS is formatted, All the paragraphs of copy I put onto any given page get broken up into columns and it is very frustrating and I haven't a clue ...
0
votes
0answers
13 views

Check if currently viewed page is displayed by site specific template

I am working on plugin. Is it possible to check if the currently viewed page is viewed through a site-specific template? As described here: https://docs.craftcms.com/v3/localization.html#step-4-...
1
vote
1answer
27 views

How can I retain entry category filtering on entry pages' pagination

I have a list of entries, with an option to filter them by categories. If no filter is applied, clicking an entry should (and does) take you to the permalink URL for that entry, as defined in the ...
0
votes
1answer
24 views

Multiple Relations Trouble

I'm having trouble setting entries with multiple relations. during testing I've hard coded the theme to 1 specific category {% set themeID = "12309" %} {% set theme = craft.categories.group('...
1
vote
1answer
19 views

Image not found with some transforms in english locale

I'm working on a page that has 2 different locales. The German locale is perfectly fine but in the english locale some assets that use the transforms seem to not be working at all. Funny thing is this ...
1
vote
1answer
54 views

Just upgraded to Craft 3, environmentVariables changed or stopped working

In my Craft 2 install, I had many links in Twig templates like this: <link rel="stylesheet" href="{{ craft.config.environmentVariables.baseUrl }}assets/css/styles.css"> I recently upgraded to ...
1
vote
1answer
50 views

.htpasswd in template file

I would like to set a .htpasswd on a folder within my templates directory. Here is what I did: ..create the .htpasswd file and place in directory above my public folder ..create a .htaccess file that ...
1
vote
2answers
25 views

How to reference a user related to entry input in if statement

I am having trouble referencing a user in an if statement: {% set otherEntry = craft.entries().section('other').userFieldInOtherEntry("{externalVariable}").one() %} {% if currentUser is relatedTo(...
1
vote
1answer
55 views

How to reference specific asset subfolders in Craft 3

I am having trouble referencing specific subfolders in Assets in Craft 3 using Twig. The query that I've written is still showing all content, when I only want it to show content from a specific ...
0
votes
0answers
23 views

Matrix field not displaying after updating to Craft 3

According to the documentation, this should loop through all Matrix fields. {% for block in entry.fieldname.all() %} But it's showing nothing. Everything is showing in the CMS itself, but not on the ...
1
vote
1answer
42 views

Create a dynamic select element

I want to build a dynamic html select element that includes the prior five years, given the current year. So, since it is now 2020, the result would be: <select> <option value="2015">2015&...
0
votes
0answers
41 views

How can i get the current applied route in CraftCMS?

I'm using a dynamic route that loads a template. I'm on a multisite setup with a language switch in the header menu. To be able to switch between sites or languages, the dynamic routes need to have ...
1
vote
1answer
33 views

How do I render pages with dynamic content from a json feed

I am building a module to show a job/vacancy-list and the detailpage of a job, the data is fetched from a remote json feed. Currently I have the following routes to a controller in my module return [...
2
votes
1answer
67 views

Revisions limit

To extend the revisions limit I currently edit the "vendor/craftcms/cms/src/templates/_includes/revisionmenu.html" file. But I have to do it after each Craft CMS update. Is there a better way to do ...

1
2 3 4 5
31