Movable Type 4: How can I show the last asset? - movabletype

I know i can use
<mt:EntryAssets lastn="1">
<img src="<$mt:AssetThumbnailURL width="100"$>" />
</mt:EntryAssets>
to show the 'last' asset...how do I show the 'first' or 'oldest' assest?

[I'll point out here that "first" and "oldest" are not necessarily the same question.
You'll see why this is important below. Given the snippet you used, I'm going to assume what you're asking for is first as in position within the entry content. Sorry for length, but this is one of my pet bugs.]
Technically, you can't. That bug(summarized further down if you don't have an Fbz account) has finally been attached to a milestone, so hopefully this won't always be the case.
Practically, reversing the sort order will usually probably output what you expect:
<mt:entryassets limit="1" sort_order="ascend">
...as long as you compose your entries top-to-bottom, and don't later mess with the assets much
The underlying problem is that the current EntryAssets implementation doesn't actually take your content into account. It just loads a list of associated assets and then sorts them by the created_on dates of the assets themselves, not what physical order they appear in or even when they were attached to that particular entry. So as an extreme example, if you insert five images into a post, my snippet above will return the first image, as expected. If you later reverse their order and save, it'll still output that same image, which is now the (ordinal) last one. So, back to what I said at top, you're thinking "first" and MT is always giving you "oldest." And this requires an even further assumption that you're always uploading the assets at time of composition. If one of them was already in the system from say, two years ago, it's going to get returned because it's just older than everything else.
If you're using MT4.3x with the Entry Asset Manager in the sidebar of the composition screen and use it to attach(rather than insert) assets, this is going to get even more complicated, because there's no way to distinguish between assets that were associated with the entry via each manner.
So.
If you absolutely need the returned asset to be predictable, you'll need to actually distinguish it from the group in some way. There's this suggestion to tag the asset with "#first" or something similar. It's not great, but you'll at least know what you're getting(assuming you only tag one asset per entry as such). If you've got custom fields available, you might see if it makes more sense to create a separate "featured/thumbnail image" asset field that it would go into so that you could explicitly test for it. It'll ultimately depend some upon why you're wanting to extract this particular asset.

Related

Get value within TV’s html attribute in Modx

I’m new to Modx so I don’t know if this is possible or not.
My TV, in this case [[*myTV]] outputs the following:
<data value='www.mylink.com'>Description</data>
Is there a way to only display the data value in the front-end? In this case I just want to display the url.
My recommendation would be to keep the data (in this case the URL) and the html separate, and that might help your situation. If the TV only includes the URL itself, then it makes it much easier to deal with the output of the TV using output modifiers. As an example, if [[*myTV]] contains www.mylink.com for a particular resource and you want the original output in your question, you could do something like:
[[*myTV:default=`<data value='[[*myTV]]'>Description</data>`]]
You can also nest TVs within output modifiers, so if for example you had a corresponding [[*description]] TV that describes the URL in [[*myTV]], you could use:
[[*myTV:default=`<data value='[[*myTV]]'>[[*description]]</data>`]]
TL;DR... The short version: Storing the entire output in the TV and extracting text from within that TV to output is much more difficult than storing individual components of that output in separate TVs and bringing them together for output when needed.
The longer version: In any situation where you're storing both data and HTML in a TV (which is not advisable in the vast majority of cases), you'll likely find duplication of your data across your project, and if by chance you decide to change the html at some point in the future, you then have to go into each and every TV field and change that HTML, which is the opposite effect from what a CMS is supposed to do - i.e. make Content Management easier!
If you do happen to find a use case for storing TVs along with their HTML formatting, that is a job best left for MODX Chunks, where you can code the implementation of your TVs within HTML in one spot within MODX and instead of duplicating that code everywhere, you reference the chunk like so: [[$chunk]].

How can I make Content Items without a CommonPart appear in the content list?

I created a custom Type that has a UserPart attached to it.
According to this issue on GitHub you can't add a CommonPart to content that also has a UserPart because it causes a StackOverflowException but I would still like items of my custom Type to show up in the content list. I already store CreatedUtc and PublishedUtc in the custom PartRecord, can I manually plug these in somewhere?
EDIT: For clarification, my specific scenario is that I am building a public facing Orchard website based on existing data that was used in a private application up to this point. I have a legacy table with user accounts that need to be mapped to Orchard Users but they also represent travel agencies that visitors should be able to browse and that Orchard admins should easily be able to edit and create through the Dashboard. I got the idea to create a TravelAgency type with a UserPart from Sipke's webshop tutorial
Content Types do not require to have a CommonPart to show in the Content List. If i remember properly its done by triggering the Creatable() in your migrations.
Also if you have a UserPart, you could Lazy loaded or just reference it via Foreign Key.
Why would you like something like that to be part of the Content List? I usually keep my business-specific Content Types tucked away in a nice section, so there are easier to visualise and use for users.
There is definitely a bug but as they comment you could extend taxonomies to accomplish your task and keep in mind sometimes changing the Orchard Codebase might fit your purposes, you only have to keep track of your changes when you upgrade next time. I have done it a couple of occasions to fit my projects.
If i remember properly, its been a while.. If you look in the core code where the Content List is created it looks for Creatable() Types. digging even more inside the code, chances are the Query in charge will join the CommonPart, hence your problem. You could easily add another query in the controller and add whatever you are after. The problem though, will be refactoring the rest of actions to accommodate your your type too. Way easier isolating your new Type. had to look at it for you, check this baby: Orchard.Core.Contents.Controllers.AdminController

Search Algorithm for a web application that needs to look for a specific value

I'm developing a webapp that will need to download the html form a website and then iterate through the code and try to find a specific but ever changing value (in our case it will be the price for the product).
For this, I was thinking about asking the user (upon installation and setup) to provide the system with a few lines of html from the page (that has the price) and then from then on, every time we need to fetch the price we would try to search for those lines and find the price.
Now, I believe this is a horrible and slow way of doing this and since there are no rules and the html can be totally different from one website to another (even the same website might change) I couldn't find a better way.
One improvement that I thought about was to iterate through the first time and record the line at which we find the code. Once found, the subsequent times we would then start from a few lines before the expected location and start the search. Any Thoughts on how I can improve on this?
I posted this question on https://cstheory.stackexchange.com/ but they commented that it's not on topic and that I should post it here.
I have the code for the above and if needed I can post it, I'm simply thinking that there must be a better, faster way of doing this.
This is actually something I tried for a project recently (using BeautifulSoup and Python). The solution that worked for me was to workout CSS selectors (which can map to jQuery selectors) that targeted the elements that contained the values I was looking for. In my case I was able to narrow down the full document to just the elements that contained what I was looking for but if you couldn't get exactly what you where after you could combine this with some extra lactic like test to see if it looks like a price (via regex) or test what it is next to.

can an opengraph object be multi-page?

I've searched a lot for the answer to this question - but can't find one - possibly it is just too stupid, in which case please forgive me!
I want to add og metadata to our pages, but the information for each logical object (in our case a sports team or player) can be spread across multiple actual URLs (eg /team/, /team/players/, /team/results/ are all logically part of /team/).
Can I put the same opengraph metadata on multiple pages that represent the same object?
Or alternatively, can I specify the og:url as a regex, eg: /team/* ?
Or does /team/ imply /team/* for an og:url ?
Thanks very much for any clarification, Mike
the information for each logical object (in our case a sports team or player) can be spread across multiple actual URLs (eg /team/, /team/players/, /team/results/ are all logically part of /team/).
Do you mean all of these URLs contain the same information (they are just different points of access to that info) – or do you mean the info is spread in „bits and pieces” over these URLs (and a user would have to visit them all to get all the info)?
I’m not sure I understand your question/problem here – but maybe you’re just looking for what’s called a canonical URL …?
You could call in every subpage the Open Graph API passing the parent page as object; no need to put metadata also on subpages, if you are not interested in having subpages as separate objects. This way, a like clicked on an individual page is always given to the team. You might use a custom property to specify from where the click arrived (or even the ref property, maybe).
On a side note, I would not tell that results are logically part_of the team. Although for this specific usage, it does not matter.

Dividing long content to subpages

I need to divide long content to sub-pages.
Rule for dividing: Heading1 (H1)
Cms-system: MODX Evolution
As far as i know, there is nothing in modx to use for this kind of problem.
I probably got to do this manually anyway, but i still would like to know if there is a way to do this in MODX Evo / Revo.
Edit:
I need to do this in MODX; sub-pages got to be actual subpages, and original page becomes to container.
Navigation will be done with wayfinder.
Edit2:
All done.. manually. Question still open, though.
This is not possible out of the box and I don't know of any extra that archieves what you want. You would have to write a plugin that acts everytime you save a resource and split up the content, create/delete sibling resources as needed etc. Sounds like a lot of work for what you want to archieve to me.
I suppose you have a look at the MIGX extra. It provides you with a TV with the possibility to store an indefinite amount of distinct TV content sets. Have a look at the documentation and Mark Hamstra's tutorial (with screenshots) to see how it is done. You should define one MIGX entry to consist of a text field for the <h1> and a rich text field for the content of the "subpage".
Afterwards, you can use form customization to hide the original content field and display your MIGX Tv instead.
I think, this is a much easier way to archieve, what you want, and can't think of any way, where you would benefit from actual subpages.
Edit: Sorry, I just recognized that you were asking about Evolution, not Revolution. My solution would work in Revo, but I don't think there's something like MIGX for Evo. Sorry, my mistake.
not 'out of the box' you will have to run your content through a snippet to parse it into separate divs or something that you can run some javascript on to possibly 'tab' the content.
If you need to show the 'subpages' in your navigation, you will probably have to use the gatResources extra to parse your content ~ which will be very expensive on resource usage.
You can (depending on how you're using the tree) just create actual sub resources under the parent resource, using Ditto or Wayfinder to build navigation for it.
If you can't use the tree like that (though from your description I think you can), you could also set up a number of template variables ("content1", "content2", "content3" etc) and show that with a simple snippet or so.

Resources