Skip to main content
5 votes

Loop divisible by issue

Forgive me if I'm wrong... by using loop.index0 is divisible by(2) are you trying to determine if the instance is odd or even? 1st - returns false 2nd - returns true 3rd - returns false 4th - returns ...
Jamie Wade's user avatar
  • 3,644
5 votes

Change custom element Index title via getTableAttributeHtml?

I finally found the answer to this question. From BaseElementType defineAvailableTableAttributes() docs, The first item that this array returns will just identify the database column name, and ...
Anya Dit's user avatar
  • 366
5 votes

How to override homepage content through plugin?

You can inject HTML to the end of the body using View Events: use craft\web\View; use yii\base\Event; Event::on( View::class, View::EVENT_END_BODY, function() { echo 'Foobar'; } ); The ...
MoritzLost's user avatar
  • 11.6k
4 votes
Accepted

Cannot remove index.php from URLs either

In this case, the Apache mod_rewrite module wasn't installed, so the <IfModule mod_rewrite.c> block of Craft's default .htaccess file was being skipped not allowing index.php to be rewritten in ...
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

Reusing logic to set string variables

I would use macros. A Twig macro is basically a function, that can take arguments and render HTML. Macros can be defined inline (i.e. in the same template where it's used) or in a separate file (...
Mats Mikkel Rummelhoff's user avatar
4 votes

Loop divisible by issue

What you want is not the loop variable of the inner loop around the image, but the loop variable of the outer loop. To get to the outer loop, use loop.parent. Try this: {% if loop.parent.loop.index0 ...
Marion Newlevant's user avatar
3 votes

Custom CP Element Indexes

For the second part of your question, look into Element Sources. You might be able to pull off something fancy in a module, where certain users have access to different sources. For the first part of ...
Lindsey D's user avatar
  • 24k
3 votes

How do you programmatically update an asset index?

This is what I ended up with which works great for me. $ses = craft()->assetIndexing->getIndexingSessionId(); $src = craft()->assetIndexing->getIndexListForSource($ses, 7); for ($i = ...
Trevor Orr's user avatar
3 votes

Update Asset Index in Batches

After seeing this and hitting the same problem ourselves, we decided to create a plugin to index the assets from S3 in batches. We have not yet moved to using tasks in the plugin but it is on our ...
Matt Shearing's user avatar
2 votes
Accepted

Copy of subsite is still serving index.php in the links?

You should have the setting 'omitScriptNameInUrls' => true on either both sites, or in the wildcard config. <?php return [ '*' => [ // ... 'omitScriptNameInUrls' => ...
Jordi Kroon's user avatar
2 votes
Accepted

How do I target the 3rd entry and only that entry?

As soon as you apply .all(), the variable you're working with becomes an array. Which means that the .offset(2) needs to be applied before you convert it into an array. UPDATE As @andrew.welch ...
Lindsey D's user avatar
  • 24k
2 votes
Accepted

Custom Module: new element type index page access

Since this is a module rather than a plugin, you need to register control panel template roots, like so: Event::on( View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, function (...
andrewmenich's user avatar
2 votes
Accepted

Getting an zero index and count for an entry list

There's an easier way... Twig has a built-in variable in for-loops called loop, which has loop.index and loop.index0 properties which output exactly what you're looking for: https://twig.symfony.com/...
James Smith's user avatar
  • 5,344
2 votes

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

You can use the slice filter but it will return an array, so you either have to loop the result or access the first index {% for item in array|slice(1, 1) %} {{ dump(item) }} {% endfor %}
Robin Schambach's user avatar
1 vote

Search query ignoring custom fields in search in search index

Do you have a queue runner that executes queue jobs? The search index command only creates queue jobs to perform the indexing, they still need to be executed. Check Utilities -> Queue Manager to ...
MoritzLost's user avatar
  • 11.6k
1 vote

Update Search Index on Entry create and update

This should actually happen automatically. After saving an entry a queue task is created which updates the search index. You could verify if this also applies to other fields (especially text fields) ...
Matthias Redl-Mann's user avatar
1 vote

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

I think you can do {{ myarray[1] }} or even {{ myarray.1 }} A more convoluted way would be to loop through the items and on the second pass, get the value. {% set secondValue = null %} {% for value ...
foamcow's user avatar
  • 2,029
1 vote

Getting an zero index and count for an entry list

I have managed to figure it out. I will use the following and it seems to work fine {% set indexCounter = ( counter | default(0) ) %} {% set counter = ( counter | default(0) ) + 1 %} Hope this can ...
Adam's user avatar
  • 255
1 vote
Accepted

Why does index.php persists in my URL?

It was the single quotes around 'true' in the config file :)
Dave Joyce's user avatar
1 vote

Get a specific entry by its index or number?

I don't know whether you've seen the batch Twig filter? You may find if useful to accomplish exactly what you are trying to do, but with a little bit less hassle. From the example in the link above: ...
Steve Holland's user avatar
1 vote

Removing index.php strange issue

Could you double check your General Settings (Settings > General) to make sure there's no "/index.php" in the Site URL field?
Matt P's user avatar
  • 1,548
1 vote

Blog pages not indexing SEO

Well, this isn't a Craft issue. You can submit a URL to be indexed via the "render" tab in Google Search Console. IIRC not all will necessarily be indexed straight away, even if submitted by itself, ...
joe's user avatar
  • 449
1 vote

Blog pages not indexing SEO

Just because Google has not indexed your pages doesn't mean there isn't necessarily anything wrong. Have you gone into the group Google search console to see what pages it has actually consumed? Also,...
andrew.welch's user avatar
  • 11.6k
1 vote
Accepted

Update Asset Index SQL Error

That error indicates a problem with the data in your database. The craft_assetfolders table has a parentId column that is a foreign key reference to its own id column. For whatever reason, that ...
Brad Bell's user avatar
  • 67.5k
1 vote

Update Search Index on Entry Save

Craft has always updated the search index automatically after an entry is saved. The exact time it does that depends on what version of Craft you are using, and how the entry is being saved (web or ...
Brandon Kelly's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible