Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
15 views

Impossible to access an attribute on a null variable - on the one() methode - 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
0answers
27 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
30 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
20 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
31 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
20 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
15 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
18 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
40 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
27 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
27 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
16 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
33 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
15 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
16 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
23 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
23 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
39 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
44 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
23 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
26 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
22 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
38 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
37 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
45 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
vote
1answer
28 views

Group by related entries field

I have a channel of Musical Compositions: Now all these Compositions have a Composer. All the composers are stored in a separate channel and then linked with their respective compositions trough a ...
1
vote
1answer
15 views

Error while accessing an associative array

Here is the code: {% if entry_name not in data and entry_total > 0 %} {% set data = data|merge({ (entry_name) : entry_total }) %} {% else %} {% set data.entry_name = 10 %} {% endif %} ...
0
votes
0answers
12 views

Twig Shipping same as Billing Address

Is it possible to write a twig conditional if the Billing Address is not the Same as the Shipping address? {# something like #} {% if order.shippingAddress is the same as the billing address %} {...
0
votes
0answers
39 views

Twig template does not show css from AssetBundle

I am building a custom module based upon the pluginfactory.io skeletons. I have registered my asset bundle and have verified my asset bundle is cached in the cpresources folder. But, the twig ...
2
votes
0answers
60 views

PHP types for Twig in PHPStorm

As this tip (Twitter) suggested we can use type hints for Twig in PHPStorm after installing Symfony Support plugin by utilizing its PHPTypes feature, for example putting: {# @var craft \craft\web\...
0
votes
0answers
19 views

Twig - How do I set a value in a non-traversable object from a variable that is passed-in to the template?

I am using the wheel-form plugin to populate a custom db table. I am retrieving the existing form data (if it exists), from inside the action controller and passing them as a variable to the template....
1
vote
2answers
27 views

Querying across relationships in a template

I have two Sections on my site: Country and Alert. The Alert section has a relation with Country via an "Entries" field. An Alert represents something that is happening in a particular country for a ...
1
vote
1answer
49 views

Reuse items from array with forloop

I have a loop of a list of regions on a project, this could be an infinite list of areas as my client's customer-base grows. The project branding has four key colours, I have these in an array: {% ...
1
vote
0answers
39 views

Is there a way to include partials in Craft without setting a path?

To separate code and avoid duplication I am trying to split up recurring pieces of twig code into partials (think of a nav or a block of services for example). I tried using include but Craft ...
0
votes
0answers
59 views

Craft and Algolia

I am trying to implement Algolia into Craft 3 and am having a few headaches. I am using scout to update my indexes which seems to be working as expected and am using the instantsearch.js ...
2
votes
1answer
31 views

How to get image url from matrix field

I have an image in a matrix-field, but can't get the url from it. dump(block.image.one().url) says NULL. My code is: {% if entry.hero %} {% for block in entry.hero %} {% if block.type == 'hero'...
0
votes
0answers
10 views

Rendering a Wheel-Form from a controller passing variables vs Rendering a Wheel-Form and calling controller actions via js?

I've been working module concept, using Wheel-Form. I can use the Wheel-Form(WF) plugin to save forms in the WF database, so the basic functionality is working. I want to: 1) use Wheel-Form to ...
1
vote
1answer
38 views

SPA style entry rendering, SEO implications

I'm working on implementing a layout that involves a listing page, that when an entry is clicked, the content slides in from the side and fills the screen. Doing this in the style of an SPA via ajax ...
2
votes
1answer
38 views

Pass aspect ratio as variable into imager

I use imager to transform images and I want to pass the image ratio as a variable: {% set customRatio = 1/1 %} {% set image = craft.assets().one() %} {% set transformedImage = craft.imager....
1
vote
1answer
34 views

Set Up Route to Template - then variable Entry is undefined

I've got a blog listing channel set up where I'm trying to filter entries listed by the entries field blogAuthors based on url segment. /articles-and-excerpts/ loads the blog fine added a route but ...
1
vote
1answer
17 views

A for loop within a for loop that is split

Possibly a bad question title...sorry but wasn't sure how to describe it. Basically I have a for loop that every 4 items I want to pull in a different item from another loop. This is a series of Q&...
1
vote
1answer
26 views

Related Entries Relationships

I am building a site where I have users, companies and content. Currently my users are standard Craft users, and my companies and content are entries within a channel. I have a field in my content ...
0
votes
0answers
14 views

Flexible List Template for Entry Types

Not sure what I'm missing here or maybe it's not as simple as I think it is, but I'm trying to create a listing template for entry types and I don't want to create a template folder or file for each ...
0
votes
0answers
23 views

Ordering merged entries

I have a requirement where I need to display entries from one channel, but entries get might show up 5 days after post date, show up if externalListingOnly or show up immediately if ...
1
vote
2answers
23 views

Impossible to invoke a method on array. How to merge multiple objects and keep as objects

{% set newsletterImages = newsletter.imagesCongratulations|merge(newsletter.imagesCis)|merge(newsletter.imagesSection3) %} {% set transformedImages = newsletterImages %} {% for image in ...

1
2 3 4 5
30