Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
I have an issue with the "exists" tag in that it appears that it doesn't recognize absolute paths.

These Absolute paths don't work:
Code: Select all
<cms:exists "/couch/uploads/image/mypic.jpg" />
OR
<cms:exists "http://thisdomain.com/couch/uploads/image/mypic.jpg" />

Only relative path works:
Code: Select all
<cms:exists "../../couch/uploads/image/mypic.jpg" />

I'd prefer the absolute to the relative for the sake of future coders (including myself) looking at it and wondering "relative to WHERE???", not remembering that it's relative to the snippets folder.

Another issue: what if I subsequently move the snippets folder?
Fair concern. All I can say that cms:exists, like cms:embed are intended to work with snippets. If you want to check files you can do it too, but as a bonus :) I think a special new tag could be great to check files. <cms:get_file/file_exists/check or similar names come to mind with parameters to start search from root or a certain folder.

I wonder what is your use-case. I never used it to check files, other than snippets.

if I subsequently move the snippets folder?

After change in config.php the place of snippets folder will be different and any urls that depend on it will cease to work.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
After change in config.php the place of snippets folder will be different and any urls that depend on it will cease

Even more reason to not rely on the location of snippets! I would suggest that the tag is satisfactory and it relates to the php file_exists() function. The one change that would be needed is to allow the tag to properly process an absolute path as the php function does. Otherwise it should be noted in the docs.
I still don't get your use-case. I am sure if someone places a snippet in snippets folder then this tag is saving a lot of hassle. No matter where the location is, the code will never stop working.
With absolute paths it is not that realistic.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
I now think that we can expand cms:exists and cms:embed to become 'smarter' and look in 3-4 predefined folders. The ones we most often use are 1. snippets 2. uploads 3. assets 4. ??

Admin can define these folders location in config.php and tags would look for the files in a defined order - first in most important folder, then if not found in next folder etc.

Some part of this functionality delivers cms:smart_embed tag, so maybe we can do something similar for files.

I think your desire to have manageable locations which will be independent and important at the same time can be praised. We have such a powerful tool in our hands to remember locations of files. <cms:exists 'logo.png' /> should be just enough without any paths (with known ordered list of folders to visit).
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
After change in config.php the place of snippets folder will be different and any urls that depend on it will cease to work.

Even more reason to not rely on the location of snippets!

<cms:exists /> checks for the existence of a file relative to the 'snippets' folder and is meant squarely to be used in conjunction with <cms:embed /> tag that also searches for snippets exactly like this.

@wysocki, I think your concern is that if you change the snippets folder, the existing code using embeds will break.

That is not so.

Consider the following code -
Code: Select all
<cms:embed 'test.html' />

Assuming the 'snippets' folder is at the default location of 'site/couch/snippets', the code above will use the file 'site/couch/snippets/test.html'.

If later on you decide the change the snippets location to now place all snippets in 'site/some-folder/some-sub-folder', the cms:embed would still work just the same. It will now use the file 'site/some-folder/some-sub-folder/test.html'.

I agrre with @trendoman's later remark -
I am sure if someone places a snippet in snippets folder then this tag is saving a lot of hassle. No matter where the location is, the code will never stop working.
With absolute paths it is not that realistic.

We'd be in trouble if we had used an absolute path for the snippet in the code above and would have had to modify all <cms:embed> code.
6 posts Page 1 of 1