Newbie to modx and I am trying to build an image slider in Modx Revo. I am using Get resources but it does not output the template file. What am I doing wrong? This is my code:
[[getResources?
&resources=`[[*slide-img]]`
&parents=`-1`
&depth=`0`
&limit=`0`
&tpl=`slides`
&sortby=`FIELD(modResource.id,[[*slide-img]])`
&sortdir=`ASC`
&includeTVs=`1` &processTVs=`1` &tvPrefix=`tv.`
]]
From what I understand, you're trying to get all images from ressources in the resource tree. And show them in an image slider.
I guess you will have the javaScript for the image slider already present. So there is how to get the images.
You have a TV called slide-img, right? Good. Make sure it's output format is text.
If you refer to that image inside of a page that carries that TV, you call it like this
<img src="[[*slide-image]]" alt="some Image" />
If you call it in a chunk (what you will do when using getResources), you call the image like this:
<img src="[[+tv.slide-image]]" alt="some Image" />
See the difference? * is for the TV inside of the same page, + is the correct call for a placeholder. So if you're using getResources, it will put everything you query into the placeholders in your microtemplate (we call that chunk in MODX terms)
So your getResources call might look like this:
[[getResources?
&parents=`-1` (the place from where getResources will dig down the tree)
&depth=`0` (how deep will it dig?)
&limit=`0` (only the default 5? no! :) )
&tpl=`slides` (this is your chunk, right?)
&sortby=`FIELD(modResource.id,[[*slide-img]])` (you will sort by the file name and folder, is that right?)
&sortdir=`ASC`
&includeTVs=`1` &processTVs=`1` &tvPrefix=`tv.` (right, right, tv. is already the default value)
]]
getResources is a snippet used primarily to list documents, not images. A document (of type HTML, XML, CSS or JSON, to name a few) is created in the document tree in the manager and represents an example of a resource that you can get with getResources snippet.
Even if it is possible somehow to put an image as a document (which I doubt), it is not a common way anyway. Usually you want to attach an image to a document via template variable of corresponding type. For a slider particularly, you need many images, not one. So, you might need something specific like Gallery Extra to manage and output your images. Check out gallery section too. Note that basic version of MODX you have just installed isn't fully functional. We have to install extras to use MODX properly. Usually I install up to 30 extras.
Also your snippet call looks weird to me:
&resources=`[[*slide-img]]`
I don't know what the content of your template variable slide-img is but it should be a comma-separated list of resource ids like 2,4,6,34. Probably, in your case you have something different like image url and the snippet call silently crashes or just outputs nothing.
Related
In my custom page type, you can select an uploaded file. That's fine, but in my ascx transformation, i'm having a hard time getting the URL. The field is 'Process'.
Here's what i currently have.
<%# IfEmpty(Eval("Process"),"N/A","<a href=" + Eval("Process") +" target='blank' class='icon download'>Download</a>")%>
When rendered, the html is this:
Download
I'm missing something.
You can use either of the 2 methods below. Both have their downfalls though.
<a href="<%# GetFileUrl("Process", "Something") %>"Link here<a/> this will
Downfall with this is if there is no value in the "Process" field, it will return an invalid URL. So I tend to use something a little better (but not much)
Item to download
This will create a valid URL with some invalid properties to it. Meaning if there is no value in the Process field, it will return 00000000-0000-0000-0000-000000000000. If the NodeAlias field is empty, it will return "download". So again, not 100% fool-proof but it works well in most cases.
Update
Check out this link:
https://devnet.kentico.com/articles/options-for-file-fields-in-structured-data
I think the piece you need in here is in the "CMS.File page type" section:
This is the link to the picture
Check out transformation methods reference
You can use <%#GetImage(Eval("Process"))%>. This will return an Image tag. There are a couple other parameters for sizing if you want to use those.
See the "Transformation reference" link on your Trasnformation editor, it goes to all the available transformation methods you can use.
In it it shows:
This will generate an actual image tag. If however you want a link, it usually is
/getattachment/<%# Eval("TheImage")%>/ImageFileNameCanBeAnythingThough.jpg
example:
/getattachment/1936c69d-a28c-428a-90a7-09154918da0f/Christmas.jpg
I've figured out how to get the image link:
{{ node.myfieldname.entity.uri.value }}
I've been poking around with kint for a bit now, but can't figure out if there is a srcset anywhere.
When loading the image normally through {{ content }} it does display a srcset, so it should have one. Just not sure if it is already available on the page.html.twig or where to find it.
The actual goal is to retreive the image srcset to use the image as a background. I'm trying to retreive multiple images to use as backgrounds for multiple div's that are defined in my page--front.html.twig
Getting access to all the node information at the page template level generally means large and painful selectors and extra rendering. It's generally easier to create a helper function and hook within your theme file to make the values easier to access.
Depending on the details of your use case the Background Image Formatter module may do what you need without much custom code.
If that approach doesn't work for you consider a template_preprocess_node() to find and extract the values you want from the field. You can move them into simple to use variables for the template.
Solved this by creating a custom block for my image, that only shows the image.
Then added the custom block to my page.html.twig
Not the prettiest solution, but easy and effective.
I have a page I'd like to embed a news-feed widget into (so that the feed from some remote site will be displayed in my site).
While there are quite a few free news-feed widgets available out there (a partial list is here: http://allwebco-templates.com/support/S_script_newsfeed.htm), They all require insertion of complex code into the html page, while all the parameters are hard-coded into the generated code, which looks something like this:
insertedWidgetText = "<script id=\"scrnewsblock10795953\" type=\"text/javascript\">...script specific parameters go here...</script>"
let feedWidget = toWidgetBody [hamlet|#{preEscapedText insertedWidgetText}|]
This doesn't integrate well with Yesod's approach as it requires specifying to Hamlet that the content is preEscapedText, which in turn disables the ability to use Hamlet's processing to alter parameters of the widget dynamically (So in case I want the widget to use a different source, for example, I need to statically change the quoted text and cannot use Hamlet's variable substitution).
Of course I could do some text manipulation myself, tailor built for the widget I'm using, but that doesn't seem like the "right" solution (especially if I want to have the embedded text in some external file and not in the middle of my code as in the example above).
Can the above mentioned issue have a better solution than the one I thought about?
Is there an implementation of a news-feed widget in Haskell/Yesod that I can use as a plugin?
Note: I'm a very poor javascript programmer, but solutions in that direction are also welcomed.
Thanks,
hi I've made a simple module with CTLModuleMaker in CMS made simple, in the template I call the necessary items like this:
{assign var="item" value=$itemlist[0]}
{$item->name->Label()}: {$item->name}<br/>
{$item->image->Label()}: {$item->image}<br/>
{$item->image_text->Label()}: {$item->image_text}<br/>
{$item->image_desc->Label()}: {$item->image_desc}<br/>
{$item->img_thumb->Label()}: {$item->img_thumb}<br/>
{$item->catagory->Label()}: {$item->catagory}<br/>
as you can see i call an image with {$item->image} but when i try to do something like this {$item->url} it returns the url of the whole page I'm trying to get the url of the image not the whole page.
any suggestions what i can do??
In a news template, it calls
<img src="{$item->file_location}/{$item->image->value}" />
You can also use {debug} to see all the variables being passed to the template in a separate popup window. This is my get out of jail free card when I can't find a field name.
If I load a string containing HTML into a UIWebView, and that string contains objects (hyperlinks) that are relative to that string, i.e. , where there is some object with id "something," then the link works - click on it and the web view jumps to the referenced object.
What I want is to get navigation to a different file in my project, in other words as though the path to the different file were a URL.
I have found that if the href IS a URL, such as href="http://www.amazon.com", then the link works.
If I put the name of a file, OR the [NSBundle mainBundle] pathForResource: ] of that name, in the href, then the link does not work.
Is there some way I can generate the equivalent of a URL pointing to an HTML file that is in the project, so that an can link to that HTML file?
I found a solution at this link:
How to use Javascript to communicate with Objective-c code?
Essentially, the solution is to implement the UIWebViewDelegate protocol's shouldStartLoadWithRequest method, and "trap" a particular value of scheme. So my links, instead of saying something like:
<a href="http://someplace.location">
are like:
<a href="mylink://#filename.ext">
By catching attempts to load anything with scheme "mylink," I can use:
[[request URL] fragment]
within shouldStartLoadWithRequest, and get the filename.ext. I then release my previous UIWebView, load in the contents of the specified file, and make that the contents of a new UIWebView. The effect is that the links work with normal appearance, even though they are being implemented with my code. I return NO because I don't want the usual loading to take place. If the scheme is NOT mylink, I can return YES to allow normal operation.
Regrettably, I still have no way to jump TO a fragment within a web view. In linking to a real URL, you can say something like "www.foo.org#page50" and jump straight to wherever an object on the new page has an id of "page50." With my method, I can only go to the top of the page.
This is also not going to give me a "go-back" function unless I record the filenames and implement it myself.