Symlinks and Static Resources

Symlinks

What are they?

The ModX website describes symlinks as below:

"A MODx Revolution symlink simply takes the content of one resource and displays it in another."

This means you can have two different urls that display the same content.

Why use them?

The more I used ModX the more I found getResources really useful. It took a while to wrap my head around it at first, but, once I did, I discovered it can be used as a useful to display a variable amount of content.
For example, I have a page with various cards - when you click on a card a modal pops up with particular details depending on the card you picked. I wanted these cards to be easily customisable, and not be restricted by the number of template variables I code in.

I created a template which would be the main page. I then created a template which would be used for each of the feature items - this was mainly to hold the template variables I would need. But now I have a new document for each of these features - it has a url which I can travel to but the template it uses doesn't have any html so its a blank page. This is how its supposed to look - noone should be travelling to this page. But I wasn't comfortable with this being accessible on my site. Unpublishing or hiding from menus won't help. This is where I decided on a symlink.

I changed the resource type to symlink and the symlink value to the parent page.

Sure, I could have used a redirect, and have done so in some places of my site, but this felt like a nice way to maintain the visibility of the structure of the site. If someone is interested in that feature, they can still travel to that url - but it now shows as complete page.

One thing to note - symlinks create duplicate content which is not ideal for search engine optimisation! Here it is wise to use a canonical link in the header. Read more about SEO in this beginner's guide.

Static Resources

What are they?

"A Static Resource is a Resource abstraction of an actual file on the filesystem."

These means you can have a url that displays a document.

In Use

Again, I found Modx's getResources useful as a way to show a variable amount of content. In this case, it was an amount of pdf customer case studies. By using a static resource, I can give the document a template which can then have it's own template variables needed for the getResources tpl. The resource then also has a readable url, rather than the full name of the pdf file.

To get the pdf displaying correctly I used the below settings.


Comments

Popular posts from this blog

Eliminating Spam in Modx Forms

Effective Form Design