Drupal8:Rendering multiple TWIG template

I meet this situation as i wanted to add some hard coded text bevor the pagination table. It is just a demonstration how to render multiple TWIG templates within one return and can be useful to add third party code like external services (RSS, Webservices …)

The “custom_html_content_page” template theme should be defined in mymodule.module file, something like:

And finally the TWIG template in the templates folder:

OUTPUT:

Headline

Lorem ipsum …

Drupal8:Basic Jquery Ajax custom module controller

In the previous tutorial (drupal8-create-module-with-multiple-route-and-custom-route-contoller-twig-template/) we have create a custom modul using different Route and some TWIG templates. Now  we want to call one of the route using Ajax .

First of all, we should have create a custom theme and add our custom JavaScript file in MY-THME.info.yml :

Now we have to define the “global-scripting” in the MY-THME.libraries.yml

In js/ajax.js we add the usual Jquery ajax code

Let explain what we have define in the js/ajax.js:
1. The HTML Link to click:

2. Then we have to prevent to reload the page with: event.preventDefault();
3. We get the content of the href attribute, because this will be the Ajax Route call:

4. Now we start the Ajax call , we will add a post variable, that indicate our controller that we are comming from an ajax request.
5. We set the URL in the browser with the Route using:

Why we do this ? Simple , if Google will index our link or user disable Javascript in the browser , we have then to be sure that the link will works without the ajax call . In the Controller we will have a condition using the post variable “ajaxCall”.
6. The Controller response will then displayed in the content div.

 

So now we have to extend the editContact($id) Method within the custom module Controller “ContactController”:

You will be able now to call your own Business Logic, extend and transfer your variables to the TWIG tempalte.
IMPORTANT: Don’t forget to define your variables first in mymodule.module . Clearing the cache if no changes can be very helpful.

drupal8: create module with multiple route and custom Route Contoller Twig Template

In the most example of drupal8 you will experiment the Hello World module. This is just a demostration how you can create your custom module within the new drupal8 concept.

But your application can be more complicated as just a Hello World module, you want may be create one module, multiple route and a custom twig template for each route

User case is if you want to create your own module but managing a multiple Route within one module.

When you add a new yaml file you should uninstall the modul and insatll it again. I haven’t found other solution for this right now ! This will help you if you can’t see any changes when you add some configuration or yml files.Or when you get following error:
Theme hook YOUR-TEMPLATE not found.

Let say you want to create a module to manage contact and edit them. My Module in this case is named “mymodule”

Let start to create the diffrent route in “mymodule.routing.yml” file:

 

Add your Conroller in src folder with the name ContactController.php:

Create following yml file “mymodule.module”:

At the end just create the Twig templates within your templates folder:

templates/contact_edit.html.twig

templates/contacts_show.html.twig

So now, you are able to create diffrent routes and templates using Drupal8 and transfer variables from the controller to the twig template
using your own business logic operations.

Drush8 Drupal8 on unix system

First install composer for all projects(Required User root)

Then change directory to to the Drupal8 installtion and edit composer.json and add the drush line:

at the end update compser with: (Required User www-data)

if permissions Problem:

 

clear cache with: (Required User www-data)

or if you have your own site:

Upgrade PHP 5.5 to 5.6 and PHP Warning PHP Startup Unable to initialize module

How to upgrade PHP to 5.6 is not a big challenge. In some cases , some manuell installed modul over pecl like imagick will not properly works. This is because some modul are compiled with the old  php module.

The error looks like:

So the new php 5.6 in this case is compiled with module API=20131226 . All what you have to do is to upgrade the php5-dev package and reinstall the modul again. In this case imagick.

That’s all.

Basically, if you want to install imagick for the first time you can use the following commands:

Add File imagick.ini in :
/etc/php5/cli/conf.d and
/etc/php5/apache2/conf.d
With content:

mysql_secure_installation – mysql-5.5 wheezy-security; urgency=high

Ifyou get following message during server upgrade:

Then you have to run following command to secure and restrict your Database aceess.

The test Database will be deleted and also the anoymous user access from the localhost.

multipart_chunk_size_mb – upgrade s3cmd from 1.0.0 to 1.5.2 AWS Ubuntu 12.04.3 LTS

if you get some of the following errors , you should upgrade the s3cmd from 1.0.0 to 1.5.2:

[Errno 104] Connection reset by peer
[Errno 32] Broken pipe

The Problem is that files with size more han 5GB will not be able to be uploaded to AWS S3.  It is recommended that s3cmd  should be updated to 1.5.2 . This update gives the possibilitities to split / chunk the uploaded file.

Update to the recent s3cmd Version

1. Backup your /root/.s3cfg file
2. Get the latest Version with:
wget http://sourceforge.net/projects/s3tools/files/s3cmd/1.5.2/s3cmd-1.5.2.tar.gz
3. tar zxf s3cmd-1.5.2.tar.gz
4. cd s3cmd-1.5.2/
less INSTALL
5. apt-get install python-setuptools
6. python setup.py install
7. s3cmd –version
If this doesn’t work , then :  cp -a s3cmd /usr/bin/
8. s3cmd –version
9. s3cmd –configure

You can see now new options like : multipart_chunk_size_mb

Example:

Symfony2 installation version2.6 on amazon AWS Ubuntu OS

VirtualHost for the DEV and PROD environement: Please read the comments (#) and adapt to your system.

############DEV env################

##change to your web path####
DocumentRoot /srv/www/tests/symfony2.6/htdocs/web
##change to your web path####

Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# add your .htaccess data here####
##


DirectoryIndex app_dev.php


RewriteEngine On
RewriteRule ^/bundles/ - [L]
RewriteRule ^/css/.*\.css - [L]
RewriteRule ^/js/.*\.js - [L]
RewriteRule ^/robots\.txt  - [L]
RewriteRule ^/config\.php  - [L]

RewriteRule .* /app_dev.php


LogLevel error
##change to your logs path####
ErrorLog /srv/www/tests/symfony2.6/logs/error.log
CustomLog /srv/www/tests/symfony2.6/logs/access.log combined
##change to your (sub)domain ####
ServerName dev.sym26.local.de


############Prod env################

##change to your web path####

Options FollowSymLinks
AllowOverride None



DirectoryIndex app.php


RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by apache
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule ^/bundles/ - [L]
RewriteRule ^/css/.*\.css - [L]
RewriteRule ^/js/.*\.js - [L]

# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]




# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead


##change to your web path####
DocumentRoot /srv/www/tests/symfony2.6/htdocs/web
##change to your (sub)domain ####
ServerName prod.sym26.local.de

LogLevel    error
##change to your logs path####
ErrorLog      /srv/www/tests/symfony2.6/logs/error_prod.log
CustomLog     /srv/www/tests/symfony2.6/logs/access_prod.log combined


ModPagespeed off