I've been working on a new client's website, and they have been using ModX for a while, so I started working with it as is .. I've dabbled with other CMS's and none of them impressed me, and I went into this with an open mind, but skeptical. Turns out, I love ModX, it's powerful, flexible and for the most part easy to use. However, there is one problem that I'm trying to figure out how to solve.
I have furl working properly on Win7/IIS (or at least properly enough, but that's a topic for another separate thread). And, so, with the page name, I have a corresponding image that I would like to show, seems simple enough to throw in the [[Alias]] variable, and work with that. However, some pages don't have corresponding images, and I would like to know if I should use TV's, or some other method of showing the proper image when there is one and not showing the stupid blank placeholder icon when there isn't a corresponding image?
you can create a little 'fileexists' - snippet, which checks for the existence of the file and does only return the img-tag, if it exists.
@bruno - do you have a reference for this FileExists snippet?
@micro - I tried looking at TV's, but I couldn't get a grasp of them. Am I able to fill in the TV with a specific value from an individual page? If so, how would I do that?
didn't try this, but something like that schould do it:
snippet:
<?php
//[[chunkIfFileExists? &tpl=`myImgTpl` &filename=`[[+pagetitle]]` &filepath=`assets/images/`]]
$properties = $scriptProperties;
$properties['file_url'] = $modx->getOption('base_url').$filepath.$filename;
return file_exists($modx->getOption('base_path').$filepath.$filename) ? $modx->getChunk($tpl,$properties) : '';
chunk myImgTpl:
<img src="[[+file_url]]" />
your snippet-tag:
[[chunkIfFileExists? &tpl=`myImgTpl` &filename=`[[+pagetitle]]` &filepath=`assets/images/`]]
if it works you can put more properties and get them as placeholders in your chunk.
@Micro - I'm using Revo. Thanks
@Bruno - I'll have to save this method as a back-up in case I can't get it to work otherwise. I'm not that familiar with Java coding, but if it comes down to it, I known enough "programming" to search on-line and find something close enough to work and tweak it to my needs, if it doesn't meet my need as-is. Thanks
@Micro, Okay, I've got you so far, I've created the variable (I called it 'myImage' because I try not to use any variable name that could possibly be a 'reserved word'). And I completely understand your IF statement - what it does, etc., but how do I actually fill the variable with the filename of the picture I want to use for each different page?
I have named the images to correspond with each page, but not every page has an image, so as I mentioned before, for those pages that don't have images, I'm getting the placeholder icon showing up.