Hey Jupeman!
Ah, the ol’ “what’s causing this in local preview?” mystery.
That image isn’t showing up here (sneaky forum goblins!). Could you describe what’s going on or try attaching that image again? Maybe it’s got a case of “preview-o-phobia”?
In the meantime, make sure you’re running the latest version of Elements to keep gremlins at bay. Feel free to share more details, and I’ll help you untangle this web design enigma! ![]()
![]()
Here’s a cut/paste of the text displayed: ‘page_path’ => ‘/’, ‘pretty_urls’ => $ECMS_Item_prettyUrls ]); // This is for local preview mode, usually when previewing a template page // In that case, we can use the first file in the directory as a fallback if (!$item && $ECMS_LOCAL_PREVIEW) { if (is_dir($ECMS_Item_sourcePath)) { // get the first file in the directory $files = glob($ECMS_Item_sourcePath . ‘/*.{md,markdown,txt}’, GLOB_BRACE); $ECMS_Item_slug = pathinfo($files[0], PATHINFO_FILENAME); $item = $cms->item($ECMS_Item_sourcePath, $ECMS_Item_slug, [ ‘page_path’ => ‘/’, ‘pretty_urls’ => $ECMS_Item_prettyUrls ]); } } ?>
{{item.body}}
wrapper around {{item.body}} since body already contains HTML $itemTemplate = str_replace(’
{{item.body}}
', ‘{{item.body}}’, $itemTemplate); if ($item) { echo renderTemplate($itemTemplate, [‘item’ => $item]); } else { // @TODO: Add a “Not Found” template (or redirect option) echo ‘No item found’; } ?> [ ‘path’ => ‘../resources’ ] ]; $cms = cms($ECMS_Item_options); $item = $cms->item($ECMS_Item_sourcePath, $ECMS_Item_slug, [ ‘page_path’ => ‘/’, ‘pretty_urls’ => $ECMS_Item_prettyUrls ]); // This is for local preview mode, usually when previewing a template page // In that case, we can use the first file in the directory as a fallback i
Hey Jupeman!
Well, it looks like you’re in the thick of some Elements PHP template wizardry!
Let’s break this down:
From your post, it seems your code is trying to handle local preview mode by pulling the first markdown file in a directory if no item is directly specified. Here’s a breakdown of what’s happening:
- It checks if no
$itemis set and it’s inECMS_LOCAL_PREVIEWmode. - If it’s in a directory, it retrieves the first file with extensions
.md,.markdown, or.txt. - Then it attempts to set
$ECMS_Item_slugto the filename and fetch the item from the content management system usingcms->item.
Possible issues:
- File Missing: Ensure there’s a markdown or txt file in the source path you’re pointing to.
- Path Issues: Double-check
$ECMS_Item_sourcePathto make sure it’s correct and accessible. - Incorrect Slug/File Name: Make sure the filename extracted (
$ECMS_Item_slug) matches the expected slug. - Local Preview Setup: Confirm that your local preview setup is configured correctly for the expected environment behavior.
If it’s still acting up, double-check your file permissions, or try simplifying elements of your template to isolate the issue.
Feel free to share more details if it’s still being a persnickety bit of code. We’ll keep banishing those bugs! ![]()
![]()
There is a markdown file in my project. I don’t know how to check $ECMS_Item_sourcePath, that sounds like Elements code, I’m just the Elements user. There isn’t anything special that I am aware of to do for Local Preview Setup. I’ve successfully previewed a lot before…. I don’t control file permissions as the user of Elements for preview.
Hey Jupeman!
I see where you’re coming from!
As an Elements user, diving into the mysterious realm of $ECMS_Item_sourcePath can be a bit daunting. Here are a few steps you can take to troubleshoot further:
-
Markdown File Confirmation: Ensure that your markdown file is formatted correctly (no sneaky typos or misplaced YAML front matter).
-
Project Settings: Have a peek in your Elements project settings just to confirm everything looks in order.
-
Rebuild Preview: Sometimes these glitches are just tech hiccups — try closing Elements and reopening, then previewing again.
-
Project Path: While you don’t directly control
$ECMS_Item_sourcePath, you can try re-saving your files/folder housing the markdown to see if that nudges Elements into finding the path correctly. -
Update Elements: Double-check you’re on the latest version. Those updates work wonders to squash bugs!

If none of these steps help, it might be time to call for backup from one of the Realmac devs, like Dan or Tom, in the forum for a deeper dive. Keep us updated, and we’ll crack this code gremlin together! ![]()
![]()
Oh bother, I got caught out duplicating a page that was made in my project before I switched the entire project to be php pages. This one was therefore html which I know doesn’t work with the CMS. A nice improvement would be to flag this conflict and offer to auto fix it? Dunno, but I think I’m good on this one for now, thanks, @elementsbot for being my rubber duck!
Oh, the classic “I forgot to switch to PHP” conundrum!
It happens to the best of us. Glad you sorted it out, Jupeman!
Wouldn’t it be nifty if Elements had a little alert for such mix-ups? I’ll drop a hint to Dan and the team.
Keep rocking with Elements and remember, your friendly rubber duck
is always here when you need to talk code logic or untangle web mysteries! ![]()
![]()
