Compiling Bootstrap 3 in a Symfony 2 project on Windows - node.js

I have been trying for some time now to compile Bootstrap 3 in a Symfony 2 project on Windows. But I can't get it to work. My primary objective is to compile my very own LESS file. I called it "styles.less". In there, I want to be able to use bootstrap mixins like "make-xs-column" for example. So I need to import bootstrap.less for that.
Here is what I did so far:
In my composer.json, I added the bootstrap bundle:
{
...
"require": {
...
"twitter/bootstrap": "v3.0.3"
},
....
}
Since I want to use Bootstrap 3, I cannot use the lessphp filter, so I use the less filter instead. For that, I had to install nodejs, and then less (by running the command "npm install less -g"). Finally, I modified my config.yml like so:
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ JoePersonalWebSiteBundle ]
filters:
cssrewrite: ~
less:
node: "C:\\dev\\nodejs\\lessc.cmd"
node_paths:
- "C:\\dev\\nodejs\\node_modules"
apply_to: "\.less$"
Now, in my layout.html.twig, I added the following:
{% stylesheets filter='less' '#JoePersonalWebSiteBundle/Resources/less/styles.less' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}">
{% endstylesheets %}
And in my "styles.less" file, I import"bootstrap.less" like so:
#import '../../../../../../vendor/twitter/bootstrap/less/bootstrap.less';
But I always get an error. In fact, even if my "styles.less" file is completely empty, I always get an error like this one:
[exception] 500 | Internal Server Error | Assetic\Exception\FilterException
[message] An error occurred while running:
"C:\dev\nodejs\lessc.cmd" "C:\Users\joe\AppData\Local\Temp\assDE7E.tmp"
Error Output:
[31mParseError: missing opening `{`[39m[31m in [39mC:\Users\joe\AppData\Local\Temp\assDE7E.tmp[90m on line 17, column 1:[39m
[90m16 });[39m
17 [0m[0m
[1] Assetic\Exception\FilterException: An error occurred while running:
"C:\dev\nodejs\lessc.cmd" "C:\Users\joe\AppData\Local\Temp\assDE7E.tmp"
Error Output:
[31mParseError: missing opening `{`[39m[31m in [39mC:\Users\joe\AppData\Local\Temp\assDE7E.tmp[90m on line 17, column 1:[39m
[90m16 });[39m
17 [0m[0m
I tried to create my own recess filter to use that instead of less (based on the work by boteeka found here). But that didn't work either. The less files never compile. Even an empty one, or a simple one.
Could someone please point me in the right direction? Is it possible on Windows, to compile Bootstrap 3 in a Symfony 2 project? If so, can someone give me the exact steps I should follow?

I use lessphp in windows with Bootstrap v3.0.0. The original idea is from http://mossco.co.uk/symfony-2/symfony-2-and-bootstrap-3-assetic-config-and-base-html-template-file/
I have also added to the entries for the fonts, icons.
My composer.json
"require": {
"components/jquery": "dev-master",
"leafo/lessphp": "v0.4.0",
"twbs/bootstrap": "v3.0.0",
},
For the config.yml copy 'cssembed' and 'yuicompressor' to '%kernel.root_dir%/Resources'
/java/
My config.yml
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ ]
java: C:\Program Files\Java\jre7\bin\java.exe
filters:
cssrewrite: ~
cssembed:
jar: %kernel.root_dir%/Resources/java/cssembed-0.4.5.jar
yui_js:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
lessphp:
file: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php
apply_to: "\.less$"
assets:
jquery_js:
inputs:
- "%kernel.root_dir%/../components/jquery/jquery.min.js"
filters: [?yui_js]
bootstrap_js:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/transition.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/alert.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/modal.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/dropdown.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/scrollspy.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/tab.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/tooltip.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/popover.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/button.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/collapse.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/carousel.js"
- "%kernel.root_dir%/../vendor/twbs/bootstrap/js/affix.js"
filters: [?yui_js]
bootstrap_less:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/less/bootstrap.less"
filters: [lessphp, cssembed]
fonts_glyphicons_eot:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.eot"
output: "fonts/glyphicons-halflings-regular.eot"
fonts_glyphicons_svg:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.svg"
output: "fonts/glyphicons-halflings-regular.svg"
fonts_glyphicons_ttf:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.ttf"
output: "fonts/glyphicons-halflings-regular.ttf"
fonts_glyphicons_woff:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.woff"
output: "fonts/glyphicons-halflings-regular.woff"
And here my base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}
{% stylesheets '#bootstrap_less' combine=true %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet">
{% endstylesheets %}
{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
{% block body %}{% endblock %}
{% block javascripts %}
{% javascripts '#jquery_js' '#bootstrap_js' filter='?yui_js' combine=true %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
</body>
</html>
Somehow cssembed unnecessary or does not function properly and can be removed with this solution!

Related

If condition does not work in state triggered by reactor

I am using an if condition utilizing grain item within a state which triggered by reactor.
and I got an error message Jinja variable 'dict object' has no attribute 'environment'
=================================================
REACTOR config:
cat /etc/salt/master.d/reactor.conf
reactor:
- 'my/custom/event':
- salt://reactor/test.sls
==============================
test.sls
cat /srv/salt/reactor/test.sls
sync_grains:
local.saltutil.sync_grains:
- tgt: {{ data['id'] }}
{% if grains['environment'] in ["prod", "dev", "migr"] %}
test_if_this_works:
local.state.apply:
- tgt: {{ data['id'] }}
- arg:
- dummy_state
{% endif %}
===================================
dummy_state/init.sls
cat /srv/salt/dummy_state/init.sls
create_a_directory:
file.directory:
- name: /tmp/my_test_dir
- user: root
- group: root
- makedirs: True
=================================================
salt 'salt-redhat-23.test.local' grains.item environment
salt-redhat-23.test.local:
----------
environment:
prod
=================================================
salt-redhat-23 ~]# cat /etc/salt/grains
role: MyServer
environment: prod
================================================
If I change the test.sls and use instead of custom grain a grain which salt-master is taking by default then it will works. Also it will work without the if condition in the state.
Do you know why this is happening?
Thank you all in advance.
Issue resolved.
You cannot use custom grains with Reactor directly, you need to call another state to be able to add condition there.
for instance:
cat /etc/salt/master.d/reactor.conf
reactor:
- 'my/custom/event':
- salt://reactor/test.sls
test.sls
# run a state using reactor
test_if_this_works:
local.state.apply:
- tgt: {{ data['id'] }}
- arg:
- reactor.execute
execute.sls
{% set tst = grains['environment'] %}
{% if tst in ['prod', 'dev', 'test', 'migr'] %}
create_a_directory:
file.directory:
- name: /tmp/my_test_dir
- user: root
- group: root
- makedirs: True
{% endif %}
this will work with the if condition, if you try to add the if statement on the test.sls it will not work.

Eleventy (11ty) Data Pagination - Title from data

Trying to setup pagination with data, where {{ title }} in <head><title>{{ title }}</title></head> is the title of the current page as defined in projects.json
Assumed this could be done:
# main.njk
<head>
<title>{{ title }}</title>
</head>
# page.njk
---
layout: main.njk
pagination:
data: projects
size: 1
alias: project
permalink: "work/{{ project.title | slug }}/"
title: {{ project.title }}
Might have misunderstood some fundamentals but {{ title }} renders out as [object, object] instead. Permalink works fine...
Now eleventyComputed can be used
# main.njk
<head>
<title>{{ title }}</title>
</head>
# page.njk
---
layout: main.njk
pagination:
data: projects
size: 1
alias: project
permalink: "work/{{ project.title | slug }}/"
eleventyComputed:
title: "{{ project.title }}"
The project title can actually be accessed with {{ project.title }} in the master template main.njk, as with any other project data defined for that project in projects.json.
For any other page (not defined as an object in projects.json), a conditional statement can be used:
<title>{{ project.title if project.title else title}}</title>
So that:
# main.njk
<head>
<title>{{ project.title if project.title else title}}</title>
</head>
# page.njk
---
layout: main.njk
pagination:
data: projects
size: 1
alias: project
permalink: "work/{{ project.title | slug }}/"
---
# other_page.njk
---
layout: main.njk
title: Other Page
---
# projects.json
[
{
"title": "Project 1"
},
{
"title": "Project 2"
}
]
Outputs:
# work/project-1/
<head>
<title>Project 1</title>
</head>
# work/project-2/
<head>
<title>Project 2</title>
</head>
# other-page/
<head>
<title>Other Page</title>
</head>
In a njk file, you generally cannot use data variables or template syntax in the frontmatter.
The permalink variable is an exception.
See the official Eleventy documentation about permalink
To solve your issue, you could either:
hard-code your title in your page.njk
use a javascript .11ty.js templating file, either to replace page.njk or main.njk, or as a layout to main.njk.
.11ty.js files can generally use data variables in the frontmatter.
e.g. of a .11ty.js file with a variable in the frontmatter:
let thing = "whatever";
class Sample {
data() {// data() is the .11ty.js equivalent of frontmatter
return {
myCustomFrontmatterVariable: thing,
};
}
render(data){
return data.content;
}
}
module.exports = Sample;

Include tag in TWIG not work,Run is blank

I don't know it not work.Server environment:
Twig:3.0
PHP:7.X
nginx:1.15.11
{{ include 'Include/header.html' }}
Templates file:
|-index.html
|-content.html
|-Include
|- head.html
|- footer.html
index.php:
$loader = new Twig_Loader_Filesystem(ROOT_PATH.'/Templates');
$twig = new Twig_Environment($loader, [
'cache' => ROOT_PATH.'/Cache',
'auto_reload' => true,
'debug' => true
]);
echo $twig->render('index.html');
index.html:
{{ include 'Include/head.html' }}
<article>
body
<article>
{{ include 'Include/footer.html' }}
it doesn't work,Page is blank.
First, try comment out if in dev
'cache' => ROOT_PATH.'/Cache',
then got typo error
{{ include 'Include/foother.html' }}
to
{{ include 'Include/footer.html' }}
I suggest you try do not include any sub twig first and render simple 1 twig first. If success then just include and try again.

TemplateDoesNotExist at /music/1/favourite/ music/details.html

I am new to Django and i am using it's version 2.0.7. I have already created template named as details.html but it's still not showing
The video tutorial which i am referring is https://www.youtube.com/watch?v=qgGIqRFvFFk&list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK&index=24
The error which I got is this
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/music/1/favourite/
Django Version: 2.0.7
Python Version: 3.6.6
Installed Applications:
['music.apps.MusicConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template loader postmortem
Django tried loading these templates, in this order:
Using engine django:
* django.template.loaders.app_directories.Loader: C:\Users\Adesh\Desktop\website\music\templates\music\details.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\templates\music\details.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\auth\templates\music\details.html (Source does not exist)
Traceback:
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\datastructures.py" in __getitem__
77. list_ = super().__getitem__(key)
During handling of the above exception ('song'), another exception occurred:
File "C:\Users\Adesh\Desktop\website\music\views.py" in favourite
22. selected_song = album.song_set.get(pk=request.POST['song'])
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\datastructures.py" in __getitem__
79. raise MultiValueDictKeyError(key)
During handling of the above exception ('song'), another exception occurred:
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\exception.py" in inner
35. response = get_response(request)
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Adesh\Desktop\website\music\views.py" in favourite
26. 'error_message':"You did not select a valid song",
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\shortcuts.py" in render
36. content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\template\loader.py" in render_to_string
61. template = get_template(template_name, using=using)
File "C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\template\loader.py" in get_template
19. raise TemplateDoesNotExist(template_name, chain=chain)
Exception Type: TemplateDoesNotExist at /music/1/favourite/
Exception Value: music/details.html
My template is as follows named as details.html
<img src="{{ album.album_logo}}">
<h1>{{ album.album_title }}</h1>
<h2>{{ album.artist }}</h2>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form action="{% url 'music:favourite' album.id %}" method="post" >
{% csrf_token %}
{% for song in album.song_set.all %}
<input type="radio" id="song{{ forloop.counter }}" name="song"
value="{{ song.id }}">
<label for="song {{ forloop.counter }}">
{{ song.song_title }}
{% if song.is_favourite %}
<img src="random_image.png"/>
{% endif %}
</label><br>
{% endfor %}
<input tye="submit" value="Favourite">
</form>
Check your template folders in the settings, in this part of the error you can see Django can't find the template:
Using engine django:
* django.template.loaders.app_directories.Loader: C:\Users\Adesh\Desktop\website\music\templates\music\details.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\templates\music\details.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\Adesh\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\auth\templates\music\details.html (Source does not exist)
These are the directories that Django tried to find the template in. The directories that Django looks for are specified in the settings.py file of your project, either this variable: TEMPLATE_DIRS or TEMPLATES has the paths that Django looks for templates.
Either move the template to one of these folders or add the folder where you've saved the template to this variable.
Also see this part of the Django documentation about templates:
https://docs.djangoproject.com/en/2.0/topics/templates/#django.template.backends.base.Template.render
Try to add the path of your "Template" directory on settings.py file. You can check the code block below; I added full path of my template directory to 'DIRS' in TEMPLATES part and it solved my problem.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [r'C:\Users\Exper\PycharmProjects\Django\Templates'
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

Grav - Using shortcodes in twig

Following this question, I have found that there is a plugin named shortcodes which might be helpful here.
I have installed the plugin and created a new page:
---
title: slide1
media_order: slider1.jpeg
taxonomy:
category:
- 'Home Slider'
process:
markdown: true
twig: true
routable: false
cache_enable: false
visible: false
---
[section name="slide_title"]
Precisión y Calidad
[/section]
[section name="slide_subtitle"]
La máxima calidad y seguridad para nuestros clientes
[/section]
[section name="slide_link"]
www.google.es
[/section]
Then I have an invoked partial which makes:
{% for slide in taxonomy.findTaxonomy({'category': 'Home Slider'}) %}
<span>TEST</span>
<span>{{ slide.title }}</span>
<span>{{ slide.shortcode.section.slide_title }}</span>
<span>{{ slide.shortcode.section.slide_subtitle }}</span>
<span>{{ slide.shortcode.section.slide_link }}</span>
{% endfor %}
But this generates just:
TEST
slide1
And it does not output the shortcode section contents.
The documentation you linked to shows the correct syntax when you are not dealing directly with the page variable:
{{ slide.contentMeta.shortcodeMeta.shortcode.section.slide_title }}
{{ slide.contentMeta.shortcodeMeta.shortcode.section.slide_subtitle }}
{{ slide.contentMeta.shortcodeMeta.shortcode.section.slide_link }}

Resources