A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

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

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
17 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
32 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
31 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
30 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
27 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
22 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
13 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
6 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
23 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
27 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
17 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
24 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
48 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
38 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
37 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
26 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
8 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
32 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
29 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
27 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
16 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
10 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
22 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
17 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
vote
1answer
29 views

How to correctly format API requests for Mandrill using Fetch plugin? Getting error “you must specify a key value”

I want to use the Fetch plugin (v 1.2.0; Craft Pro 3.3.13) to send messages from a Twig template in some circumstances. To test the setup, I'm just trying to ping Mandrill, according to the /users/...
1
vote
2answers
32 views

Matrix loop (nesting?) issue using switch

First let me say this: I'm new to Craft and Twig. So: my apologies for probably overlooking the obvious. I hope you can offer me some help... I've been trying for a couple of days to solve this puzzle....
2
votes
1answer
59 views

.first() vs. .one() in craft 3

I'm confused about the new .one() argument in craft 3 If I want to grab all entries I write: {% for entry in craft.entries.section('thing').all() %} {{ entry.title }} {% endfor %} Alls is nice ...
0
votes
0answers
10 views

Craft 2: when searching for an entry can you select an entry by a fields value?

I have an entry in the section microsites these entries all have a required field called accessCode. I have the access code in a variable. I want to load in only that entry. Is this possible without a ...
1
vote
1answer
38 views

Template output when grouping matrix blocks

I have a shared content builder matrix field that has the usual blocks: Redactor, Headings, Images, etc. A typical entry might look like this: - Heading - Redactor - Image - Redactor - Heading - ...
1
vote
1answer
38 views

Using {% cache %} tags around {% template %} includes (or in Header)

I was wondering if it makes sense to wrap these {% cache %} around {% include %} tags that call a separate file with params. Is it better to just include them in the actual file itself? For example, ...
1
vote
1answer
13 views

Show Category Title only where an entry has been included in an Entries field

I have a Category Group with an Entries field assigned so the admin can select which existing Entries should fall within a given category. An Entry can be assigned to multiple categories. On the ...
1
vote
1answer
25 views

How to check if an entry is enabled for a particular site?

Is there a way to find out if an entry is enabled for a particular site? I know there's the enabledForSite property, but it doesn't look like it accepts any arguments. Ideally I'd like to do ...
1
vote
1answer
62 views

Can I call a dynamically named variable through twig?

I am using Craft 3 with the Commerce 2 plugin. I am trying to dynamically call a variable in a twig template where this variable has to be a "placeholder" for a handle of a field inside a block ...
1
vote
1answer
24 views

What's the easiest way to generate a link to edit a given entry in Craft?

Assuming I am fetching an entry like so: {% set profile = craft.entries.id(8268).one %} What is the easiest way to generate a link that allows you to edit that entry in Craft? I know you can do the ...
1
vote
1answer
72 views

Can't get current entry's ID - Impossible to access an attribute (“id”) on a null variable

I'm trying to upgrade my website to Craft 3 and can't resolve one issue with this piece of code: {% for category in craft.categories.group('blogCategories').order('title') %} <li><a href="...
1
vote
1answer
18 views

List child categories which have entries based on the current categories

I am looking to output the child categories of a parent category. I only need to show the categories which have entries related to them. I have done this to show all categories using {% set entryIds ...
1
vote
1answer
33 views

What is the significance of craft.app.request.segments|last == _self

While reading this blog article about RSS templating, I came across the following twig code if craft.app.request.segments|last == _self I understand that the above command, in general, yields URL ...
1
vote
2answers
46 views

How could I include another template on a click with ajax?

I am a newbie with ajax and I have to display a template only when clicking on a button. This template is weighing and it will be on all pages, so I want to use ajax. Someone can help me?
1
vote
1answer
53 views

Importing Macros doesn't work

I'm trying to upgrade my website to Craft 3, so I've imported all template files and installed the necessary plugins, but I can't deal with one error. I've got a template named _layout.twig, and the ...
0
votes
0answers
6 views

Craft 3 Matrix Field customFields property 'required' and 'sortOrder' fields null

I'm trying to dynamically build a frontend form based on a Matrix field. I'm iterating over the entry.aMatrixField.customFields array which returns me an array of field objects in Twig. The field ...
1
vote
1answer
26 views

Get entries related to selected category only and not it's ancestors

The following is using commerce product entries, but I'm reasonably sure it could be any entry. With the following category taxonomy: - Category 1 - Category 1A - Category 2 - Category 3 ... If ...
1
vote
0answers
20 views

EagerLoading on category pages with different product types

I have a category template like so; {% extends '_layouts/_site' %} {% set products = craft.products .with( [ 'department', 'productImage', 'finish', 'pcd', 'variants', 'thread', '...
1
vote
1answer
25 views

How to calculate half, third, fourth?

I'm trying to calculate some image sizes for Imager. This works: {% set imageSizes = [{ height: imageHeight * 4}, { height: imageHeight * 3}, { height: imageHeight * 2}, { height: imageHeight}] %} ...
1
vote
1answer
29 views

Craft 3 CMS How to get all Channel Names/Titles

I am trying to retrieve all Channel sections' names/titles. This is snippet contains the troublesome part. {% set allSections = craft.entries.all() %} {% for section in allSections %} {% ...
2
votes
2answers
81 views

“Template not found” in live-preview

I am using docker for my local webdev and am new to Craft CMS. Currently I have a simple setup running, however, my Live-Preview does not seem to work and throws the "Template not found" error. Yet, ...
1
vote
2answers
43 views

Which twig file is being used and how?

I have a page in Craft (2.x) that displays several links and I was able to find which twig file had those links by searching the code base of twigs. Those links point to some Angular code with links ...
1
vote
1answer
32 views

How to insert widgets in Rich Text field

I want to insert widgets in arbitrary positions in one of my rich text fields. A good example would be a contact form inserted in the middle of the content. These widgets would be ad units, forms and ...
1
vote
1answer
22 views

User profile page

I'm looking to setup a profile page, displaying a users details (address etc) and they're current membership status (which will be down the Stripe Payments plugin.) I'm having some trouble getting ...