Stack Exchange Network

Stack Exchange network consists of 174 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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

0
votes
1answer
8 views

How can I get the type of a field using Twig?

I would like to loop through all the fields of a field layout tab form the current entry. This is working fine to get the field name and value: {% for fieldLayoutField in entry.getFieldLayout()....
1
vote
1answer
22 views

How do I differentiate between entries after merging an array?

I'm trying to plot entries from two different Solspace Calendars and an Entries section on one map, and use different markers for all types. Alll of the events are related to the current Entry through ...
1
vote
1answer
20 views

How to get the previous or next two entries

I have an entry which needs to display the previous two entries, and the next two. I see in the docs there's a nextSiblingOf method. That does nothing in a channel, and in a structure it will only ...
1
vote
0answers
10 views

Commerce: reading Stripe object in Craft Transaction model

I'm looking to add the credit card last four digits to my customer's frontend order history. Stripe is the gateway. The Stripe transaction object doesn't seem to be available in the Craft ...
1
vote
1answer
11 views

Get the location and id of asset volumne

Is it possible to get the location (/media) and id (1) of an asset volume from within a Craft template?
1
vote
1answer
39 views

Template loads via jQuery .load(), but no {% js %} tags are included

Inside of a modal window I'm loading a form template via jQuery .load. For reasons I don't know, the {% js %} tags that need to come with the form template are not being loaded, even though the {% js %...
1
vote
1answer
28 views

How to render a template from within a module?

I'm currently developing a module that contains a custom field and I'd like to create a template to be used in the getInputHtml method. I try using the Craft::$app->view->renderTemplate method ...
0
votes
2answers
23 views

How to display data in field type with dropdown multi select checkbox?

I'm able to get data using API but when I use checkboxField then it only display the blank checkbox without value. In Model, if($result){ if (isset($result->error)) die($result->...
2
votes
1answer
19 views

Getting all the values out of a field as array of values

I have a multi-select field in my work section I want to get the values either with the Element api as json or an array of simple values in my template.
2
votes
1answer
35 views

Targeting the first entry item

I'm using Craft 3 and have created a section (channel type) for my project entries. At the bottom of each project page I have my Prev and Next Project buttons. How do I target the first and last ...
0
votes
1answer
30 views

Craft 2 use different template for the same structure

I have a site with projects which each has a projects structure with an associated category and a number of images. The URL is set as projects/{projectCat.first.slug}/{slug} I want to use the ...
2
votes
1answer
30 views

Using a template from a plugin

I'm building a simple contact form plugin and I would like to be able to provide a default form that the developer can include in his own template. Most plugins I've seen provide the controller and ...
2
votes
1answer
18 views

Adding to default classes in a macro

I'm fairly new to using macros and haven't found anything online regarding this — sorry if this is a possible duplicate post. I've created a macro with 7 possible parameters but on different ...
0
votes
0answers
22 views

Trouble displaying multiple parameters in search

Having trouble displaying multiple parameters in search results. My query strings result in correct results when I search ?regions=white-mountains or ?seasons=spring but not when they're concocted ?...
3
votes
2answers
83 views

Load a specific file/CSS only in a certain page

I want to load a .css file only in a certain page. What's the magic code I need?
1
vote
1answer
16 views

How to display a featured image in the list of entries

I created a field which uploads an image, and I want it to display it for each of my entries inside my for loop. What's the code I should use to do it?
2
votes
1answer
10 views

What is the correct syntax for using merge to create an array of field values from an element query?

I grab some values via an element query: {% set events = craft.entries.section('events').status('live,pending').order('postDate asc') %} But I need to put them into an array for use in a Craft-...
2
votes
1answer
42 views

Caching in Craft 3 causes out of memory when including grouped for loop

I have a problem with using {% cache %}in Craft 3, although the code runs fine without caching, and it works in Craft 2. I have narrowed the problem down to the following code: {% cache %} {% set ...
1
vote
2answers
38 views

How do I target the second item in an array with Twig?

I would like to select the second position in the array below. The problem is that this number is automatically changed. So I try to do this with .index function from Twig but I can not figure it out. ...
1
vote
0answers
13 views

Access array from the static translation file

This is the scenario: I need the translations strings in both Twig and JS (For React). Of course I'm covered in the Twig part., and I don't want to maintain two different files (php and json). So I've ...
1
vote
1answer
44 views

Craft 3 Deprecation Error from Twig/Extension/Core.php. How to fix?

I'm getting a deprecation error from not using .all() to query my elements: Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before ...
1
vote
0answers
32 views

How to test if a address is on a list before it gets added? (MailChimp Subscribe Plugin)

I’m working on implementing this plugin: https://github.com/aelvan/mailchimp-subscribe-craft I’m wondering: How can I accomplish to test if an address is on the list before it gets added? And on top ...
1
vote
1answer
23 views

List only those months that have entries

I setup my archive using the Craft demo. I have a page for each year. I use MixItUp,(think Isotope) to allow a user to filter entries by month. There are simple hard coded buttons for each month. ...
2
votes
1answer
11 views

How can I sum value across entries assigned to a category for a given year across multiple years?

I have a category group named country. Each entry in posts is assigned to a country and a dollar value. dollar value is a field, NOT a table cell. On a country's given page (i.e., a category ...
0
votes
1answer
12 views

How can count and then order by the # of entries assigned to a category; and then limit to only the top 3?

**How can I modify this to orderBy the # of entries and then limit to the top 3? ** {% for categoryName in craft.categories.group('markets') %} {% set numofEntries = craft.entries.section('...
1
vote
1answer
23 views

Input Tags Template for my Custom FieldType

I created a custom FieldType that gathers data from 2 different Models. I was able to successfully display it as a Drop Down. My problem now is that there are tooo many records on my array and I would ...
0
votes
1answer
35 views

Migration to new server, left with default theme?

I have migrated a website that uses Craft CMS over to a new server. The instructions that I followed were outlines in this post: Migration of Craft CMS from one host to another The domain name in ...
1
vote
0answers
17 views

Carousel with text using Matrix blocks

I am trying to create a carousel where each slide will have a title, subtitle, and maybe a summary. I know I can create a carousel like this with a set number of slides. I would like to create one ...
2
votes
1answer
114 views

Craft 3 and Macros

re: macros I'm trying to use one for an SVG sprite. But I'm not sure what I'm doing wrong. macros template: {% macro icon(iconId) %} <svg class="icon icon-{{ iconId }}" role="img" title="{{ ...
0
votes
1answer
25 views

How can I order search results by the post date?

I want to order my search results by the post date (not the created on date). And, this did not work... {% if entries|length %} {% for post in entries.groupBy('postDate') %} {% include '...
1
vote
0answers
29 views

Is this an ok approach to building a secondary navigation?

I have a site which has multiple menus e.g. primary and utility. I've built the menus via sections and the entry type for those sections has a title and a entry field. This site requires me to show a ...
0
votes
1answer
21 views

How can I loop through my entries to export them using Beam?

I want to export my entries to CSV or JSON. Craft 2 had a plugin. I can't find one for Craft 3. I reached out to the Craft community on Slack. They suggested I try the Craft 3 plugin Beam. I ...
1
vote
3answers
47 views

Flip PDF embed inside templates

I have some 'Flip PDF' generated folders that I need only logged in users to be able to access. If I put them in templates I get the problem that the .jpg images 500. Is there a way of allowing .jpg ...
2
votes
1answer
14 views

How can I get the same random array key?

I am creating a mad libs type of global. My global set is actually called madLibs. Within that set, is a matrix field - that can have unlimited blocks. Each block only has two fields. actualRole and ...
2
votes
1answer
112 views

How do I clear deprecation errors for looping through element queries?

I am getting this depreciation messages. Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them. In the example ...
1
vote
1answer
23 views

Changes made in home page not displaying

I am new on Craft CMS and it's the first CMS I am trying. Hey guys, I apologies is this question was asked before. I went through lot of articles and I didn't get anything helpful yet. I added in ...
1
vote
1answer
9 views

Assign a number 1-N for each entry that is returned

I need to assign a # 1-N for each entry that is returned -- i.e., 1, 2, 3, 4, .... (This is for a sort plugin.) How do I template for that?
1
vote
2answers
33 views

Category not loading template

I have created a new Category on a Craft 3 website but it will not load the template specified. Have other categories all working fine and can't get this one working at all. Category Config below I ...
2
votes
1answer
32 views

Can I get entries related to one category from a specific site?

If I can get entries in a category like this: {% set entries = craft.entries.section('sectionSlug').relatedTo('categorySlug').all() %} And a entries from another site like this: {% set entries = ...
0
votes
0answers
28 views

Form in Front End Template Reference Plugin for LDAP

I am a Craft newbie, and I'm currently making a few custom templates, learning Twig, etc. My question is: in including a form in my template code, how would the form be coded (Twig or HTML)? Is there ...
2
votes
1answer
44 views

Craft 3 - Searching by date field - Calling unknown method: craft\behaviors\ElementQueryBehavior

On a website upgraded to Craft 3 - having issues pulling events by date. Error Is: Calling unknown method: craft\behaviors\ElementQueryBehavior::eventDate() The Error occurs on the last line of my ...
2
votes
1answer
15 views

How can I return the entry with the highest value?

Each entry in posts has a field called value. Value is a number. For a category, how can I return the entry with the highest value? This is not for Craft Commerce. Value represents a budget figure....
2
votes
1answer
32 views

Template for event archive

I've hacked this together to create an event archive listing, and although it works, I'm wondering if it's 'correct' or could be done more succinctly? {% set pastEvents = craft.entries.section('...
2
votes
1answer
25 views

Craft 3 Docs Group Filter Not Working

I am attempting to replicate the example from https://docs.craftcms.com/v3/templating/filters.html#group However, I am unable to access the {{ year }} in the first for loop inside the h2 element. It ...
1
vote
1answer
100 views

Breadcrumbs for Craft 3

How do you make breadcrumbs in your Twig templates for Craft 3? Unfortunately I found examples only for Craft 2
0
votes
0answers
15 views

How might I setup an Entry Type for a channel's index page? [duplicate]

I have a channel posts.. It of course has a template for the entries posts/_entry with an associated entry type. But how might I set up an entry type for the index page @ posts/index? Thanks
2
votes
0answers
25 views

Add CP Tab content into include file

I am making a plugin where I have about 10 tabs at the top. Depending on the admin users privileges they may see a subset of 1-5 or 6-10 and super admins can see all 10. The issue I am running into ...
1
vote
1answer
80 views

How do I add commas to an output that returns a list of names?

I have a simple for loop to get the names of countries from a category. {% for name in country %} {{ name.title }} {% endfor %} The output is typically returns the name of 1 country. But, some ...
1
vote
1answer
21 views

Set Variable if Current Field is Empty

I'm trying to set a variable within my templates which does the following: If this field is empty then use another field instead. I have 2x Fields called affiliateUrl and offerLink, if offerLink ...
2
votes
1answer
32 views

Check if a field a included in a Matrix block

Situation: I have a matrix with about 10 block types, 3 of which have a certain field. I want to check if the current block has that field. The field in question is a dropdown with values in all 3 ...