Skip to Content Skip to Menu

Assign a CB Auto Action to one specific page?

4 days 11 hours ago - 2 days 20 hours ago #343918 by BobBriscoe
Replied by BobBriscoe on topic Assign a CB Auto Action to one specific page?
I'm using the suggested CB Content Module approach. Having set Location: footer, no indication that the script ran and, in the source of the assigned page, the JS still doesn't appear in the head.
I also tried Advanced > Module Style: None, but that didn't change anything either.

I tried it with and without <script> tags around the javascript (I assume it's meant to be without, but it' not clear which).

For the avoidance of doubt, I've provided hyperlinks to screen shots of all the CB Content config, with pink boxes around non-defaults. (I would've attached but the uploads all failed):
oldwaydogfields.co.uk/tmp/ScreenshotFrom2026-05-15_23-05-53.png
oldwaydogfields.co.uk/tmp/ScreenshotFrom2026-05-15_23-06-48.png
oldwaydogfields.co.uk/tmp/ScreenshotFrom2026-05-15_23-07-02.png
oldwaydogfields.co.uk/tmp/ScreenshotFrom2026-05-15_23-07-39.png
oldwaydogfields.co.uk/tmp/ScreenshotFrom2026-05-15_23-07-32.png

____________

Custom Value: [cb:url location="current" /]
Operator: Ends With
Value: /booking-menu

Is this really equivalent to JS: window.location.pathname.endsWith('/booking-menu') ? or does the CB match the end of the URL, whereas the JS matches the end of the pathname within the URL (ignoring query string and/or fragment - which is what I want)?
 
Last edit: 2 days 20 hours ago by BobBriscoe. Reason: Clarified the context is CB Content Module

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 50443
  • Thanks: 8629
  • Karma: 1472
1 day 19 hours ago #343932 by krileon
Replied by krileon on topic Assign a CB Auto Action to one specific page?
I've no idea if "footer" is used by your template or not. It was simply an example. You need to use a position your template renders on whatever page you're on. Full working example below.

Global
Title: Hide
Position: Footer (Cassiopeia)
Access: Public
Javascript:
Code:
alert( 'Hi!' );
Menu Assignment
Module Assignment: Only on the pages selected
Menu Selection: Home (whatever menu item is your home menu item)
Community Builder
Load Template: No
Load JavaScript: No
Load Tooltips: No
Load Language: No
Load Plugins: No
Advanced
Module Style: none

This assumes usage of the Cassiopeia template. You should then see the alert pop up on your homepage menu item.

or does the CB match the end of the URL, whereas the JS matches the end of the pathname within the URL (ignoring query string and/or fragment - which is what I want)?

It'll include matching query parameters. Use a "Does Contain" operator instead for partial patching. Alternatively use a Code condition and use Joomla API to extract parts of the URL to match against however you need.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

1 day 18 hours ago #343938 by BobBriscoe
Replied by BobBriscoe on topic Assign a CB Auto Action to one specific page?
My config is essentially the same as the config you specify. But it doesn't do anything.

I've no idea if "footer" is used by your template or not. It was simply an example.

Yes, I know you said it was an example, but I used footer because I do have text showing in a Cassiopeia footer.
...However, thinking about it, the script I'm trying to inject is intended to catch the case where a component busts out of its iframe. There is no footer (or any positions at all?) within the iframe.

I have encapsulated an unruly third party module within an article that I assigned to the hidden menu 'booking-menu', which I wrap into an iframe using <iframe src="booking-menu?tmpl=component&...">.  I'm not sure that an isolated component has any specific position, does it? So how would I get CB Content module to inject a script into the head in this case?

If CB can't do it, I could use a third party system plugin called headTag that I have used in the past (currently disabled). But I'd rather not have a mish-mash of configs, if CB can do it.

I guess that, by using
alert( 'Hi!' );
as your example, you've confirmed that I was correct to not include <script>...</script> tags, which was the only other question I asked.

 

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 50443
  • Thanks: 8629
  • Karma: 1472
1 day 17 hours ago #343941 by krileon
Replied by krileon on topic Assign a CB Auto Action to one specific page?
Ah, I see. Yeah that makes a big difference. "tmpl=component" doesn't output any module positions. CB Auto Actions though should still work fine since that's being routed through Joomla. I would also add my own query parameter to explicitly condition against as well. Example as follows.
Code:
<iframe src="booking-menu?source=frame&tmpl=component&...">

Notice "source=frame". This would be something you can then condition against and explicitly know it's in that iframe you created. Then I'd have the below conditions.

Condition 1
Field: Custom > Value
Custom Value: [cb:url location="current" /]
Operator: Does Not Contain
Value: /administrator/
Condition 2
Field: Custom > Value
Custom Value: [cb:url location="current" /]
Operator: Does Contain
Value: /booking-menu
Condition 3
Field: Custom > Value
Custom Value: [get_source]
Operator: Equal To
Value: frame

That might work to ensure you're only outputting to that frame. Aside from that I don't know what else to suggest, sorry. Does that 3rd party extension have any Joomla events? Normally that's the best route to take as CB Auto Actions can hook into any Joomla event by just prefixing the event with "joomla_". So if it has events for the display of whatever that iframe URL is you could use that as well.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

19 hours 10 minutes ago #343959 by BobBriscoe
Replied by BobBriscoe on topic Assign a CB Auto Action to one specific page?
I've used the 3rd party headtag plugin. It's interface for adding code (in a file or inline) is similar to CB Auto Actions, but it also offers various ways to target the addition. Specifically, by menu item; user group or access level.

I didn't go with a CB Auto Action, because I would have thought that targeting by matching against a URL string would be as inefficient and 'unsafe' as my original workround (with conditions inside the javascript). By 'unsafe' I mean it relies on matching to the URL string, whereas a menu assignment is associated with the underlying database item.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 50443
  • Thanks: 8629
  • Karma: 1472
17 hours 50 minutes ago #343962 by krileon
Replied by krileon on topic Assign a CB Auto Action to one specific page?
It's possible to condition against current menu item using the location substitution. Itemid in the URL is what associates the URL with a menu item. That can be substituted in as follows.

Field: Custom > Field
Custom Field: [cb:url location="itemid" /]
Operator: Equal To
Value: MENU_ID_HERE

Should be fine since now I understand what you're trying to do more specifically with rendering inside of an iframe. It's probably also possible to just pull it from GET using [get_Itemid] or REQUEST using [request_Itemid]. I can't be entirely sure as that'd be dependent on Joomla populating those again.

I've also added a feature ticket to add a new condition option for Menu so you'll be able to just select a list of menu items and it'll handle this for you so a substitution won't be needed in the future, but for now this should work fine.

forge.joomlapolis.com/issues/9869


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum