Кнопка для редактора

In order to embed (insert) different types of files into the editor (content), the editor button plugin is required. It embeds a file or multiple files into the content according to templates that are assigned to scopes.

Here we presume that the file types are uploaded in their corresponding scopes: images in the Images scope, music in the Music scope and so on. Custom scopes also meet this requirement.

The name of the button in the editor is Embed Files.

Default Embed Templates

By default there are four standard templates that are assigned to four standard scopes.

When you click on Embed Files button Quantum Manager window will open. Select a file and click on Embed button. Embed dialog window will open where you can set different fields and choose embed template. For example for images you can set width, height and description: And for document you can set the file name: All these fields depends on templates. When you embed a file, the embed code from the template is applied and the final embed code is pasted into the content. For example, the embed code for image is looking quite simple in the content:

<img src="images/space1.jpg" alt="Space 1" width="200" />

You can adjust any template for your needs and create new templates.

You can also emded multiple files:

Managing Embed Templates

Embed templates can be changed in the editor button plugin settings. Proceed to Extensions > Plugins and search there for Button - Embed Files (Quantum Manager) plugin.

As we mentioned earlier all templates are assigned to scopes. Every scope have two sections: Fields and Templates.

Fields

Fields are dynamic blocks that are used in the templates. When you embed a file you can assign values to these fields. For example, this allow to construct attributes for HTML elements, but it's not limited to. A good example is a set of fields for Images scope: The field consists of the following elements:

Name for Template
The name of the field that you will use in the template (placeholder name).
Name
The name of the field that will be displayed in the embed dialog.
Default Value
The default value for field if nothing will be set in the embed dialog.
Type
The type of field. The following types of HTML5 fields are allowed:
  • Text - simple text field.
  • Number - allows only numbers.
  • List - the list of values. Every value should be on the own line.
  • Color - a color picker.
  • Email - allows only e-mail address.
  • URL - allows only URL address.
  • Date - a date picker.
  • Time - a time picker.

To add a field, just click on the green plus icon. Let's create a new field Class:

  • Name for Template: class
  • Name: Class
  • Default Value:
  • Type: Text

Now we are ready to build our embed code.

Templates

Templates are used to construct the embed code. Here all the magic happens.

First is the Name - it is displayed in the list of templates inside embed window.

Then there are three sections: Before, Element and After. Mostly you will use Element section, so let's start with it.

Element Section

In the element section you can add a piece of HTML that will construct an embed code for a specific file. Let's go back to our example of Images scope:

<img src="{file}" alt="{alt}" width="{width}" height="{height}" />

To use a field in the template you should use the name of the field in curly brackets (placeholder). It is the Name for Template option that you define when set up the field. For example, for image we have {alt}, {width} and {height} placeholders.

Note how we mentioned a file in the template. It has a special reserved placeholder - {file}, which is replaced with the path to a file.

Other reserved placeholders are:

  • {size} - file size in kilobytes
  • {filename} - file name
  • {type} - file extension

Now let's add one more field that we have created earlier - class. Change the code to:

<img src="{file}" alt="{alt}" width="{width}" height="{height}" class="{class}" />

That's it. Save plugin settings and let's back to embed dialog to check how the new field is displayed: As you can see we have our new Class field. And that's how the final embed code looks in the content:

<img src="images/space1.jpg" alt="Space 1" width="200" /><img src="images/space1.jpg" alt="Space 1" width="200" class="img-sample" />

Element section is repeated as many times as the number of files is selected for embedding.

Before and After Sections

These sections are used to create more complex embed codes. In Before section you define a code that will be displayed before Element section and in After section you define code that will be displayed after Element.

This allow to create templates for elements like grid or slideshow or whatever you want.

There are two ways you can use these sections:

  1. Paste your HTML code right into the sections.
  2. Use layout files with HTML code.

The first one is easy. The second one is not so easy, but it has own advantages like having piece of HTML code that can be used in the different embed templates (so you do not need to repeat it form template to template). Let's see how to make these layouts and use them in before and after sections.

  1. Create two layout files in the following location

JOOMLA_ROOT/templates/{your_template}/html/layouts/plg_content_quantumanagercontent:

before_image.php with the code:

<p>Text before image</p>

after_image.php with the code:

<p>Text after image</p>
  1. In the Image embed template add to Before section this text: {{before_image}}. And to After section add this text: {{after_image}}.

As you can see to connect the layout file with the section you should use the file name in double curly brackets.

  1. That's all. Now try to embed some image and you will see that the following code will be pasted into the article:
    [qmcontent][before]{{before_image}}[/before][item][variables][{"{file}":"images\/space1.jpg","{filename}":"joomla_black.png","{type}":"png","{size}":"4.86 kb","{width}":"","{height}":"","{alt}":"","{class}":""}][/variables][template]<img src="{file}" alt="{alt}" width="{width}" height="{height}" class="{class}" />[/template][/item][after]{{after_image}}[/after][/qmcontent]

Do not worry, this code will be replaced and you will get the desired output in your content:

Examples

Now to better understand how the embed templates are working let's take a loook on several examples. These examples will show you how simple, but in meantime powerful embed templates are. We will be using UIkit to construct sample embed code.

To add a new template simply click on the green plus icon.

Lightbox

Lightbox element allows to create a responsive lightbox gallery with images or videos.

In Element section paste this code:

<div class="uk-transition-toggle uk-inline-clip" uk-lightbox>
  <div class="uk-position-cover uk-overlay uk-overlay-primary uk-transition-fade">
    <div class="uk-position-center">
      <span class="uk-transition-fade" uk-icon="icon: search; ratio: 2"></span>
    </div>
  </div>
  <img src="{file}" alt="{alt}" width="{width}" height="{height}" uk-img>
  <a class="uk-position-cover" href="{file}"></a>
</div>

Embed window: Result embed code:

<div class="uk-transition-toggle uk-inline-clip" uk-lightbox>
  <div class="uk-position-cover uk-overlay uk-overlay-primary uk-transition-fade">
    <div class="uk-position-center">
      <span class="uk-transition-fade" uk-icon="icon: search; ratio: 2"></span>
    </div>
  </div>
  <img src="images/space1.jpg" alt="Space 1" width="200" uk-img>
  <a class="uk-position-cover" href="images/space1.jpg"></a>
</div>

Grid

Grid element alows to create a fully responsive, fluid and nestable grid layout.

In Before section paste this code:

<div class="uk-child-width-1-3@m" uk-grid>

In Element section paste this code:

<div class="{class}"><img src="{file}" alt="{alt}" width="{width}" height="{height}" /></div>

In After section paste this code:

</div>

Embed window: Result embed code:

<div class="uk-child-width-1-3@m" uk-grid>
    <div><img src="images/space1.jpg" alt="Space 1" width="200" /></div>
    <div><img src="images/space2.jpg" alt="Space 2" width="200" /></div>
    <div><img src="images/space3.jpg" alt="Space 3" width="200" /></div>
</div>

Slideshow

Slideshow element allows to create a responsive slideshow with images or videos.

In Before section paste this code:

<div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slideshow="animation: scale">
<ul class="uk-slideshow-items">

In Element section paste this code:

<li><img src="{file}" alt="{alt}" uk-cover></li>

In After section paste this code:

</ul>
<a class="uk-position-center-left uk-position-small uk-hidden-hover" href="#" uk-slidenav-previous uk-slideshow-item="previous"></a>
<a class="uk-position-center-right uk-position-small uk-hidden-hover" href="#" uk-slidenav-next uk-slideshow-item="next"></a>
</div>

Embed window: Result embed code:

<div class="uk-position-relative uk-visible-toggle uk-light" tabindex="-1" uk-slideshow="animation: scale">
  <ul class="uk-slideshow-items">
      <li><img src="images/space1.jpg" alt="Space 1" uk-cover></li>
      <li><img src="images/space2.jpg" alt="Space 2" uk-cover></li>
      <li><img src="images/space3.jpg" alt="Space 3" uk-cover></li>
  </ul>
  <a class="uk-position-center-left uk-position-small uk-hidden-hover" href="#" uk-slidenav-previous uk-slideshow-item="previous"></a>
  <a class="uk-position-center-right uk-position-small uk-hidden-hover" href="#" uk-slidenav-next uk-slideshow-item="next"></a>
</div>