How to create custom HTML Elementor wrapper section? - html

I have created several sections with plain HTML and CSS that I would like to use as "wrapper" sections for my clients to be able to populate using Elementor drag and drop interface. I have tried to do this creating a custom Elementor widget, but there is no "Controls_Manager::NAME_OF_CONTROL" that I could find that would correspond to an Elementor section or inner section. (Controls_Manager::WYSIWYG is actually just a text editor).
I've also tried creating an elementor section template that has two HTML blocks: one above and one below an empty elementor section. Like this:
---------- begin HTML (Elementor or Wordpress type) block ----------
<div class="myOpeningSectionDiv"> <!-- no, it's not just a single div, I'm using opening div as an example here for brevity -->
---------- end first HTML block ----------
---------- standard empty Elementor block with the little + button goes here ----------
---------- begin second HTML (Elementor or Wordpress type) block ----------
</div>
---------- end second HTML block ----------
This does not work, because Elementor wraps those custom HTML blocks in its own html tags which breaks things.
The closest I solution I could find is creating two templates. One template is the contents simple Elementor drag and drop contents that the client can edit. The second contains just one custom HTML block with a short-code pointing towards the first template. The client would then insert that into their page. This is not ideal because 1) When you preview the page, the contents of the shortcoded section do not show up, and 2) they have to edit that section separately from the rest of the page in the templates area and can't create other sections like it without messing with HTML directly or getting me involved.
I've been searching the internet for two days for a solution and came up short. Is this possible to do?
And no, I don't think I can use a theme page template, because I need them to be able to drag and drop other sections with elementor above and below this section.
To summorize I'm trying to do this:
[Some elemnentor drag and drop content]
<someCustomReusableHtmlIWroteHere>
[Section where you can drag and drop buttons, text, form, etc using Elementor]
</someCustomReusableHtmlIWroteHere>
[Some more elemnentor drag and drop content]
I hope I'm explaining this correctly. As far as software used: latest Wordpress and Elementor Pro.

Use Elementor PHP Hooks for this:
For example:
add_action( 'elementor/frontend/section/before_render', function ( \Elementor\Element_Base $element ) {
if('section' === $element->get_name()){
// your code here
}
} );
add_action( 'elementor/frontend/section/after_render', function ( \Elementor\Element_Base $element ) {
if('section' === $element->get_name()){
// your code here
}
} );
The only issue is that while this works on the actual rendered page,it doesn't show the extra HTML in the preview in Elementor. This seems to be an issue with the before_render and after_render hooks.

you can use Unlimited Elements for Elementor,
this plugin has functionality to create own widget with html, css and JS.
then you can re-use that widget anywhere on website.
https://wordpress.org/plugins/unlimited-elements-for-elementor/

Related

How to share anchor links with angular components on angular 14?

I have a component menu which contains a few anchor tags. Each tag brings the user to that respective page section. I am trying to share the same anchor tag among the other components.
For example, I have two more HTML components called homepage.component.html and details.component.html. For each I call the menu.component.html by its selector. Both homepage and details html components have an id for the section I wanna scroll to. Here's how it looks like:
menu.component.html
Go to content
for both homepage.component.html and details.component.html
<div class="home-content" id="content"> Here comes more code </div>
It should work just like in a non-dynamic html project, however, when the anchor tag is clicked, the url redirects to '' (which is the first/default page) and then it shows the content for the first page, instead of the current componenet I am on.
I have tried creating a function where I get the current url and using the router.navigate, I pass the parameters indicating the fragment:
menu.component.ts
currentRoute: string
scrollToItem(){
this.currentRoute = this.router.url
this.router.navigate([this.currentRoute], {fragment: 'content'})
}
menu.component.html
<a (click)="scrollToItem()">Go to content</a>
However, this function adds the id #content to the url each time the anchor tag is clicked, redirecting the user to my 404 page.
I wanted to know if there is a way to use an anchor tag on the menu.componenet.html, while all the items that have "content" as their ids in different components are going to be displayed. Hopefully I made my question clear. If there is still questions about how the error occurs I can create and shate a stackblitz project. Thanks in advance :)

How to name twig files by the region they are in?

I am using Drupal with the Commerce Module to build a webshop. I am using the Commerce Cart Block to display a cart icon with the amount of items in the cart, in the navigation bar.
Now I would also like to display the Cart Block on the Cart page, but with a different template than being used in the navigation bar.
I am using the debug mode, which let me see what I could call the file names to use them like I would like to. But above both Cart Blocks it says the same file name, so I can't output two different templates. I tried putting primary_menu-- before the navigation cart block and content-- (the region the cart block is going to be in), but they don't work.
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'commerce_cart_block' -->
<!-- BEGIN OUTPUT from 'themes/custom/verdamigo/templates/commerce-cart-block.html.twig' -->
This is shown above both cart blocks (which are on the same page). So how can I use two different templates for both blocks.
primary_menu--commerce-cart-block.html.twig
is not working.
I would like to be able to edit both the block in the primary_menu and the block in the content-region. But both carts get output with the same template.
In an effort to decouple Blocks from Displays, Drupal 8 renders a block independently of which display it's in and what region/weight it has in that display (see Twig Template naming conventions) :
Region-specific block templates are not available in Drupal 8.
This removes the ability to override block.tpl.php by region, and for hook_preprocess_block() to adjust variables based on it. Instead, core developers recommend to manage block template overrides with CSS or using additional blocks.
But you can still work around this by implementing hook_theme_suggestions_HOOK_alter() :
function SOME_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if (!empty($variables['elements']['#id'])) {
$block_id = $variables['elements']['#id'];
$block = Drupal\block\Entity\Block::load(block_id);
$region = $block->getRegion();
// Allow per-region block templating.
$suggestions[] = 'block__' . $region . '__' . $block_id;
}
return $suggestions;
}
Note : the template name should begin with "block" since you override a block template, so in your case the override file should be named block--primary_menu--commerce-cart-block.html.twig.

Highlighting "current" navigation link when using template navigation menu

I'm inexperienced at coding and trying to build a pretty simple site with some HTML and CSS in Dreamweaver. I'd like my navigation menu to highlight the current page a viewer is looking at, and I've found different ways to do this. However, to make life easier as the site evolves, I've made the navigation menu an uneditable region of a template. I'm therefore finding myself unable to make the coding changes (e.g., giving a unique class to each link or a unique body id to each page) to each page that would seemingly allow me to highlight the current page link. Thanks!
A simple way to do this is with Dreamweaver template attributes which allow you to have editable tag attributes:
https://helpx.adobe.com/dreamweaver/using/defining-editable-tag-attributes-templates.html
While editing your template, if you put your cursor on the nav item class, you could then go to Modify > Templates > Make Attribute Editable.
Then, when editing the page based on the template, you'll be able to add an active class.
You could use jQuery for this to detect a word in url:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
$(document).ready(function($) {
if(window.location.href.indexOf("contact") >= 0){
$(".contactLink").addClass("active");
}
});
</script>
<style>
.active { color: black; font-weight: bold }
</style>
contact
This could add a class to the menu item that has the word "contactLink" as a class. So long as you have this js on all pages (put it in a file rather than hard coded on all pages) it will work. If you copy the above code into a page called test.html the link is normal. change the name to contact.html and it goes black..
Give each menu item a class, and then duplicate the code above for however many items you have.
There are more dynamic ways of doing it, but if you don't have millions of pages, is a nice easy way.

Edit complete HTML of page in Drupal

We have our site running on Drupal. Now I have 2 landingpages: pages without menu's and a bit different in layout as the others. I want to edit the complete HTML of the pages in the Drupal-interface, so marketeers can easily add HTML-snippets (for testing etc), without using a developer.
How could I create an empty header and footer, and let the complete HTML be the content?
You could create a specific node type, and then use this function in your template.php :
<?php
function theme_preprocess_page(&$variables)
{
if (isset($variables['node']->type))
{
$nodetype = $variables['node']->type;
$variables['theme_hook_suggestions'][] = 'page__' . $nodetype;
}
}
It will allows you to create templates for pages (Drupal is only offering this possibility for the page content) based on node types using page--node-type.tpl.php, so that you'll be able to customize the entire page html instead of just the content.

MediaWiki - how do I create a page which auto populates a link from the current page?

Hi sorry if this a daft question (newbie), I am currently using mediawiki-1.23.1 and have been looking for a way in which to create it easy for an end user to create a page. However I would love to be able to have a link auto-created/auto populate on the current page. I currently use the InputBox extension. But it doesn't seem to allow this additional function from my research. Is this a possibility through extensions, or will this have to be done via a custom php template?
current InputBox details.
<inputbox>
type=create
width=24
break=no
buttonlabel=Create new page
</inputbox>
Any help or direction would be really appreciated.
It is impossible to create a link from page A to page B automatically if you don't "mark" something on page B. And the simplest thing you can mark is "[[Category:...]]", like Bergi said. I will use preloaded text to make it easier.
What you need
If you want page in main namespace to be the page where end users type in InputBox, you need any extension that will show content of category page such as Extension:CategoryTree, or Extension:Dynamic Page List (see also Transclude a category in MediaWiki).
Steps
On page [[Template:PreloadedText]]
Put the following content
<!-- Do not edit under this line -->
<includeonly>[[Category:CreatedFromPageA]]</includeonly>
On page [[A]]
Put the following content
<!-- Show all pages in [[Category:CreatedFromPageA]] -->
<!-- Assuming you use Extension:CategoryTree -->
<categorytree hideroot="true" namespaces="-">CreatedFromPageA</categorytree>
<!-- InputBox -->
<inputbox>
type=create
width=24
break=no
buttonlabel=Create new page
preload=Template:PreloadedText
</inputbox>
For end users
On page [[A]], they will see every page that was created via the InputBox at the top. At the bottom, they will see the InputBox. After typing pagename and clicking the button, they will be brought to the page they typed. There will be the following text existing already
<!-- Do not edit under this line -->
[[Category:CreatedFromPageA]]
As long as they don't bother with these lines, after they click save, the new page will appear on the list automatically.