I have some metadata which I'd like to process with keyword replacements - I'm looking to use ^lowercase, ^replace and ^maxwords to take an asset name like 'The quick brown Fox jumps over the lazy Dog' and give me instead 'the-quick-brown-fox'.
To do so I'm trying %asset_name^lowercase^replace: :-% (make the whole thing lowercase, replace spaces with dashes)
If I use that code in an asset listing of the assets, then I get the expected formatting returned.
However, if I use that code in the metadata field of the asset, I see instead:
<meta name="metadata-field" content="%asset_name^lowercase^replace: :-" />
now interestingly, if I change both the '^replace: :' modifiers to be replacing 'a' instead of the space I have, then it works ok, suggesting that the ^replace keyword modifier works most of the time for metadata, but just hasa problem with replacing spaces.
Am I formatting my modifier wrong? Do I need to escape the space character somehow?
Replacing spaces with ^replace modifier
I hope the missing percent sign is just a typo in the question above?
If so, just out of curiosity, can you try this instead?
%asset_name^lowercase^replace:\x20:-%
Hi, yes, the missing percent sign was a typo. I've tested this again and the problem only seems to display on the metadata screen in the admin interface, where certain keyword result in different behaviour.
With an asset name of 'this is a test of the modifer issue' setting the metadata field to %asset_name^lowercase^maxwords:3^replace: :-% shows:
<meta name="replace-test" content="this is - " />
but the more or less the same metadata of %asset_name^lowercase^maxwords:3^replace: :-% shows:
<meta name="replace-test" content="%asset_name^lowercase^maxwords:3^replace: :-%" />
If you include that metadata field in the body of the asset, it gets output as the expected results of the keyword modifier(s) - e.g. the latter metadata value gives me:
'this-is-a-'
a bit odd behaviour - but I can live with that.
Anyone have a trick for removing the trailing space character that maxwords seems to leave behind?
[quote]
Anyone have a trick for removing the trailing space character that maxwords seems to leave behind?
[/quote]
toss a ^trim in there - %asset_name^lowercase^maxwords:3^trim^replace: :-%
Thanks GJames - that works a treat.
In a twist, the problem reared it's head again - we generate an asset listing of the target files and ^replace: :-% was also failing in the asset listing.
My final solution is %asset_name^lowercase^underscore^replace:_:-%