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.
Hello,
I am trying to use the bootstrap_carousel integration with for example the following renderable array in a preprocess field:
$variables['carousel'] = [
'#theme' => 'bootstrap_carousel',
'#controls' => TRUE,
'#indicators' => TRUE,
'#interval' => $interval,
'#slides' => $slides,
];
The indicators are generated automatically in a preprocess inside the bootstrap theme. Which is great thanks for the automation.
The problem I have is that the "#target" is not passed to the bootstrap/templates/bootstrap/item-list--bootstrap-carousel-indicators.html.twig
So the data-target attributes is empty and the indicators does not work.
I think it is due to the item_list hook_theme that does not register a target variable.
I will try to make a patch (this week).
Comment | File | Size | Author |
---|---|---|---|
#7 | bootstrap-data_target_carousel-2878764-7.patch | 2.08 KB | Grimreaper |
Comments
Comment #2
GrimreaperHello,
Here is a patch that use the context variable, declared in the item_list theme, to pass the target id to the indicator item list.
Thanks for the review.
Comment #3
markhalliwellUsing context will be confusing since twig also has the global variable:
_context
.We can use
#context
internally, butitem_list__bootstrap_carousel_indicators
should be preprocessed to convert it to a normaltarget
variable from#context
.Comment #4
GrimreaperHello,
Thanks for your suggestion. I agree that a context variable can be misleading.
Here is a patch that take your suggestion into account.
Thanks for the review.
Comment #5
markhalliwellAll that's needed here is
See Variables::getContext.
This shouldn't be needed.
Comment #6
markhalliwellAlso, considering that this is a theme hook suggestion and in this base theme, I think it makes sense to call
parent::preprocessVariables()
before everything in case sub-themes add a preprocessor onitem_list
.Comment #7
GrimreaperThanks for the review.
Here is an updated patch.
Comment #9
markhalliwellComment #10
markhalliwellA new issue should be created for
#start_index
that does the same thing actually.Comment #11
GrimreaperThanks for the commit :)
Comment #12
GrimreaperOk, I will see that during the week or this weekend.
Comment #13
GrimreaperAdding follow up issue.