Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Views contextual filters have an option to "Transform spaces to dashes in URL." If this option is selected, and you try to use the argument as a token in Metatag, the dashes are included in the output. The dashes should be automatically removed since they are meant to be spaces in between words.
Comment | File | Size | Author |
---|---|---|---|
#5 | metatag-n2312905-5.patch | 529 bytes | DamienMcKenna |
Comments
Comment #1
DamienMcKennaCan you please confirm which exact token you were using?
Comment #2
herd45 CreditAttribution: herd45 commentedThe behavior described above is true for all of these tokens.
[current-page:url:args:first]
[current-page:url:args:last]
[view:url:args]
[current-page:url:args]
I should also mention that the token browser for this module does not list all of the argument tokens. The attached pic has a full list.
Comment #3
drunken monkeyThis would be rather hard to fix in this form, especially in this module, I think. If anything, this should be fixed in the Views module: when resolving a token for
[view:url:*]
, and arguments are set, the arguments could automatically be substituted for their corresponding path parts.However, this would significantly complicate the code, and probably also not be in the itnerest of everyone using these tokens, so I don't think such a patch would have a chance to be committed.
What would be possible, however, is just letting the admin use the special Views-style pseudo-tokens for arguments (i.e.,
%1
/!1
,%2
/!2
, etc.) to achieve exactly the effect you want – including the argument values (with their original spaces) in the Metatags.A patch is attached, I opted to use
hook_metatag_pattern_alter()
to implement this – it could of course also just be added tometatag_views_page_alter()
with a loop, but I guessed this would be too inflexible? Or would the performance improvement be worth it?Also, this could of course be made optional per view, if you want that. And maybe we should add this to the description somewhere.
But in principle the code works, at least for me.
Comment #5
DamienMcKennaRerolled.
Comment #6
DamienMcKennaSo yeah, we need a per-View option for this.