Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
1
vote
2answers
18 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
44 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
33 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
21 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
19 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
25 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
22 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
24 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
15 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
25 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
9 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
13 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
19 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
55 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
35 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
37 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
23 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
27 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
23 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
36 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
26 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
41 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
41 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
25 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
19 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
26 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
66 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
40 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
20 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 ...
1
vote
1answer
52 views

My month/year archive template code no longer works in 3.2 [closed]

My blog has a date archive page that uses a variation of this code. Here's the code that I've been using: {% set allEntries = craft.entries.section('entries').type(['posts','reviews']).limit(null)....
3
votes
2answers
283 views

How to access HTML input values from Twig and vice versa

I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours. I want to access the value of "foo" input field inside the twig ...
0
votes
0answers
26 views

Checking if entry field exists - dot vs bracket notation

Let's say I want to check if the field exists in entry. When I try to check for some no-nexisting field using dot notation it incorrectly returns true - entry.somefield is defined If I use bracket ...
1
vote
1answer
44 views

Get an Asset's Filename Without the Extension

How do I get an asset's filename without the extension? So if my filename is my_cool_photo.jpg I want to return my_cool_photo. Using {{ entry.assetsField.one.filename }} returns the name of the file ...
0
votes
0answers
26 views

Customizing display order of category entries to match admin (order as Structure)

I'm working on a Craft-based site that has a category defined for "Members". I can see in the admin panel one has the ability to drag the entries for this category in any arbitrary order (when ...
1
vote
1answer
28 views

Category query returning one fewer items than requested

I'm building a knowledgebase for a client. The client has asked for content to be restricted by category and then by user. This part is easy enough - the users now use the same category field as ...
1
vote
1answer
41 views

Navigation is throwing Twig error when trying to 'preview' a disabled entry

I have an entry that needs to be disabled until the content is finalized. I am not able to 'preview' the entry unless I enable it. If I remove the navigation code, 'preview' will work on the disabled ...
1
vote
1answer
56 views

Explanation of Deprecation Warnings

Why is this depreciated? Is there an example of the preferred method? Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping ...
0
votes
0answers
22 views

Double encoded querystring parameters in pagination urls

Since upgrading to Craft 3.2 I've noticed that my querystring parameters are double encoded in my pagination urls? Example below: /search/p2?s=cancer&t%255B%255D=blog Edited: After a bit of ...
1
vote
1answer
91 views

Render template from Module in twig template

I have been searching around SE and the web in general for an answer to this. There seems to be plenty of solutions but none appear to be working for me. I have a simple module that has a variable ...
0
votes
0answers
19 views

Twig Include is displaying empty modules on page

I have a twig file called "Abilities.twig" inside abilities I have the below code: <p>{{ module.Ability }}</p> In the CMS I have a field set named "modals" with the field block "...
0
votes
0answers
10 views

Feed Me Plugin - can't authenticate when using inside templates

This is in reference to Feed Me's ability to call a feed directly from within a template. My issue that the feed I am hitting requires an authentication header to be sent at the same time in order to ...