I am new in HWIOAuthBundle with Symfony2.3 +FosUserBundle.
I am using this bundle for facebook, twitter, googleplus login in my project.
I have successfully install this and this working fine.
But I want to override login.html.twig because I want to show facebook , twitter, google plus Images to our twig file but I don't know How I can do this in HWIOAuthBundle.
My login.html.twig
{% block content %}
{# Bonus: Show all available login link in HWIOAuthBundle #}
{% render(controller('HWIOAuthBundle:Connect:connect')) %}
{% endblock %}
Base HWIOAuthBundle login.html.twig
{% extends 'HWIOAuthBundle::layout.html.twig' %}
{% block hwi_oauth_content %}
{% if error %}
<span>{{ error }}</span>
{% endif %}
{% for owner in hwi_oauth_resource_owners() %}
{{ owner | trans({}, 'HWIOAuthBundle') }} <br />
{% endfor %}
{% endblock hwi_oauth_content %}
Which one showing this type in Html page:
Facebook
Google Plus
Twitter
this is show by default when click any one then redirect to his page(Facebook,Twitter,Google Plus).
But And I want to show this type HTML:
<!-- socials -->
<ul class="top-socials">
<li><a class="facebook" href="#">Facebook</a></li>
<li><a class="twitter" href="#">Twitter</a></li>
<li><a class="google-plus" href="#">Google+</a></li>
</ul>
How can I do this ?
To be more specific about your case, you should create 2 new views:
app/Resources/HWIOAuthBundle/views/layout.html.twig:
{# extends your own base template #}
{% extends 'MyBundle::layout.html.twig' %}
{% block title %}{{ 'Login' | trans }}{% endblock %}
{% block body %}
{% block hwi_oauth_content %}
{% endblock hwi_oauth_content %}
{% endblock %}
app/Resources/HWIOAuthBundle/views/Connect/login.html.twig:
{% extends 'HWIOAuthBundle::layout.html.twig' %}
{% block hwi_oauth_content %}
{# Display oauth errors (here using Bootstrap) #}
{% if error is defined and error %}
<div class="row">
<div class="col-md-12 alert alert-danger text-center">
<span class="error">{{ error }}</span>
</div>
</div>
{% endif %}
{# HWIOAuthBundle integration #}
<ul class="top-social">
<li><a class="#" href="{{ hwi_oauth_login_url('facebook') }}">Facebook</a></li>
<li><a class="#" href="{{ hwi_oauth_login_url('twitter') }}">Twitter</a></li>
<li><a class="#" href="{{ hwi_oauth_login_url('google') }}">Google+</a></li>
</ul>
{% endblock hwi_oauth_content %}
Do not be tempted to put this login page in the first file, because OAUthBundle uses several other views (to confirm profile, etc).
This example is taken from symfony-quickstart project.
You have two solutions for that :
Use bundle inheritance and refine the template with parent path
Declare a template in you app/Ressources/ like that : app/Ressources/AcmeBundle/Directory/template.html.twig (where /AcmeBundle/Directory/template.html.twig is the exact same path to the template in your vendor)
Doc :
http://symfony.com/doc/current/cookbook/bundles/inheritance.html
http://symfony.com/doc/2.0/book/templating.html#overriding-bundle-templates
Related
I am having hard time adding navbar to the github page.
I downloaded Monophase jekyll theme via this link :
http://jekyllthemes.org/themes/monophase/
I saw a navbar in the demo, but when i applied to the github.io page, I am missing navbar.
Index.markdown:
---
layout: default
---
If I set layout to default, nothing shows up and if I set to home all the posts are displaying but it does not navbar.
And there is no such thing as _data/navigation.yml in the monophase package zip I downloaded.
_site is set to .gitignore from what I received so I did not include the _site folder to the git as it was originally set, but do I need to add _site to git and create _data and navigation.yml inside this folder? to make the navigation bar?
I tried doing this but it did not work out so I'm not sure if I'm doing things right but would be nice if someone can explain what I'm doing wrong ;~;
default.html:
<!DOCTYPE html>
<html lang="{{ page.lang | default: site.lang | default: 'en' }}">
{% include head.html %}
<body>
<div class="container">
{% include header.html %}
<div>hello</div>
<main>{{ content }}</main>
{% include footer.html %}
</div>
{% if page.math %} {% include mathjax.html %} {% endif %} {% if
jekyll.environment == 'production' and site.google_analytics %} {% include
google-analytics.html %} {% endif %}
</body>
</html>
Header.html :
<header class="masthead">
<div class="masthead-title">
{{ site.title }}
<small class="tagline">{{ site.tagline }}</small>
</div>
{% if site.data.navigation %}
<nav class="nav">
<ul class="nav-list">
{% for item in site.data.navigation %}
<li class="nav-item">
<a href="{{ item.url | relative_url }}" class="{% if page.url == item.url %}current{% endif %}">
{{ item.title }}
</a>
</li>
{% endfor %}
</ul>
</nav>
{% endif %}
</header>
Home.html:
---
layout: default
title:home
---
<div class="posts">
{% assign posts = site.posts %} {% if paginator %} {% assign posts =
paginator.posts %} {% endif %} {% for post in posts %}
<div class="post">
<h2 class="post-title">
{{ post.title }}
</h2>
<time datetime="{{ post.date | date_to_xmlschema }}" class="post-meta"
>{{ post.date | date_to_string }}</time
>
<p class="post-excerpt">
{% if post.description %} {{ post.description | strip_html }} {% else %}
{{ post.excerpt | strip_html }} {% endif %}
</p>
</div>
{% endfor %}
</div>
{% if paginator %}
<div class="pagination">
{% if paginator.next_page %}
<a
class="pagination-item older"
href="{{ paginator.next_page_path | relative_url }}"
>Older</a
>
{% else %}
<span class="pagination-item older">Older</span>
{% endif %} {% if paginator.previous_page %}
<a
class="pagination-item newer"
href="{{ paginator.previous_page_path | relative_url }}"
>Newer</a
>
{% else %}
<span class="pagination-item newer">Newer</span>
{% endif %}
</div>
{% endif %}
Yes, or at least it's possible, but unclear given what you've shared.
With Jekyll on your desktop, you are locally building an html directory which would be a static version of your site. This is very likely the _site folder. If this is what you did (successfully), then the contents of that directory are a complete website; *.html files, etc.. Copy the content of this folder to your Git Pages repo, and they should work as-is. _site is in .gitignore because it is a by-product of your code, and in a sense, a duplicate, just in different format.
The advantage of this route is you can view the built html and iterate on your code more quickly, without taking your site down or testing changes live. More to the point, you can open the _site folder and view index.html or similar in your browser to see how things are working. The Demo for this style wasn't working when I tried to access it, and I wasn't able to find the source code for the default implementation (which DID have a nav bar), to be able to tell you how they set it up.
The alternative route is to maintain your Git repo with Jekyll-themed files, and Github will build the site for you. Assuming up-to-date versions, this should be the same as what you did on your desktop.
For this route, I'd suggest reading documentation on how to add a menu/navigation to your _config.yml file. This is usually where the navigation is specified, but you can certainly override it or customize a navigation in supporting css files. This is also something that you'll want to consult documentation for.
I wrote the following code:
{% extends "base.html" %}
{% block content %}
{% if all_site %}
<ul>
<h3>Here all my site:</h3>
{% for site in all_site %}
<li> {{ site.name }}</li>
{% endfor %}
</ul>
{% else %}
<h3> You don't have any Site.</h3>
{% endif %}
{% endblock content %}
when, I run. I not see "Here all my site", but I only see the one contained in the for.
I tried to modify it, for now a solution that I have found working is this:
{% extends "base.html" %}
{% block content %}
{% if all_site %}
<h3>mmmmmm</h3>
<ul>
<h3>Here all my site:</h3>
{% for site in all_site %}
<li> {{ site.name }}</li>
{% endfor %}
</ul>
{% else %}
<h3> You don't have any Site.</h3>
{% endif %}
{% endblock content %}
in this case if I do run, i see:
here all my site:
site 1
site 2
This is in regards to the Shopify Debut theme!
So my main nav has two links, About us and Shop. When one clicks on Shop, one is directed to "https://myshop.com/collections". At this stage the Shop link gets the class site-nav--active and changes color to be visibly active.
My problem:
The moment I click on a collection I am directed to https://myshop.com/collections/collection-name, but the Shop link for some reason does not stay active. How can I change that? I need to the Shop link be active the moment the URL has collections in it, and also when on the cart page. Any ideas?
I think i need to change something in this block of code in the site-nav.liquid file.
{% comment %}
Renders a list of menu items
Accepts:
- linklist: {Object} Linklist Liquid object (required)
- wrapper_class: {String} CSS wrapper class for the navigation (optional)
Usage:
{% include 'site-nav', linklist: section.settings.main_linklist, wrapper_class: 'site-nav--centered' %}
{% endcomment %}
<ul class="site-nav list--inline{% if wrapper_class != blank %} {{ wrapper_class }}{% endif %}" id="SiteNav">
{% for link in linklists[linklist].links %}
{%- assign child_list_handle = link.title | handleize -%}
{% comment %}
Check if third-level nav exists on each parent link.
{% endcomment %}
{%- assign three_level_nav = false -%}
{% if link.links != blank %}
{% if link.levels == 2 %}
{%- assign three_level_nav = true -%}
{% endif %}
{% endif %}
{% if link.links != blank %}
<li class="site-nav--has-dropdown{% if three_level_nav %} site-nav--has-centered-dropdown{% endif %}{% if link.active %} site-nav--active{% endif %}" data-has-dropdowns>
<button class="site-nav__link site-nav__link--main site-nav__link--button{% if link.child_active %} site-nav__link--active{% endif %}" type="button" aria-expanded="false" aria-controls="SiteNavLabel-{{ child_list_handle }}">
<span class="site-nav__label">{{ link.title | escape }}</span>{% include 'icon-chevron-down' %}
</button>
<div class="site-nav__dropdown{% if three_level_nav %} site-nav__dropdown--centered{% endif %}" id="SiteNavLabel-{{ child_list_handle }}">
{% if three_level_nav %}
<div class="site-nav__childlist">
<ul class="site-nav__childlist-grid">
{% if link.links != blank %}
{% for childlink in link.links %}
<li class="site-nav__childlist-item">
<a href="{{ childlink.url }}"
class="site-nav__link site-nav__child-link site-nav__child-link--parent"
{% if childlink.current %} aria-current="page"{% endif %}
>
<span class="site-nav__label">{{ childlink.title | escape }}</span>
</a>
{% if childlink.links != blank %}
<ul>
{% for grandchildlink in childlink.links %}
<li>
<a href="{{ grandchildlink.url }}"
class="site-nav__link site-nav__child-link"
{% if grandchildlink.current %} aria-current="page"{% endif %}
>
<span class="site-nav__label">{{ grandchildlink.title | escape }}</span>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
{% endif %}
</ul>
</div>
{% else %}
<ul>
{% for childlink in link.links %}
<li>
<a href="{{ childlink.url }}"
class="site-nav__link site-nav__child-link{% if forloop.last %} site-nav__link--last{% endif %}"
{% if childlink.current %} aria-current="page"{% endif %}
>
<span class="site-nav__label">{{ childlink.title | escape }}</span>
</a>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</li>
{% else %}
<li {% if link.active %} class="site-nav--active"{% endif %}>
<a href="{{ link.url }}"
class="site-nav__link site-nav__link--main{% if link.active %} site-nav__link--active{% endif %}"
{% if link.current %} aria-current="page"{% endif %}>
<span class="site-nav__label">{{ link.title | escape }}</span>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
Below are two screenshot, which I hope will help you understand my problem.
Shop link active:
Shop link not active
The link.active
Returns true if the link object is active, or false if the link object is inactive.
So the current page URL needs to match the URL in that link.
In your case:
I need to the Shop link be active the moment the URL has collections in it, and also when on the cart page.
This should do the trick:
{%
if link.active or
request.page_type == "collection" or
request.page_type == "cart"
%}
{% assign link_active_class = "site-nav--active" %}
{% endif %}
<li class="{{ link_active_class }}">
<a href="{{ link.url }}"
class="site-nav__link site-nav__link--main{% if link.active %} site-nav__link--active{% endif %}"
{% if link.current %} aria-current="page"{% endif %}>
<span class="site-nav__label">{{ link.title | escape }}</span>
</a>
</li>
This code expand on what you had before, so if the exact "Shop" link is active OR the page type is a "collection" or "cart", the link is going to be active. If none of the conditions are met the link_active_class won't be defined and class will be empty class="".
Just make sure that this code is only applied to the "Shop" link otherwise all links will be active on collections or the cart page.
Add this code
{% assign link_active_class = "" %}
{% liquid
if link.active
assign link_active_class = "site-nav--active"
elsif link.title == "shop" and request.page_type == "collection"
assign link_active_class = "site-nav--active"
elsif link.title == "shop" and request.page_type == "cart"
assign link_active_class = "site-nav--active"
endif
%}
If link is active then it's business as usual, if not
We check if the link title is "shop" and the current page type is of the desired types then we add the active class.
Make sure that the link title case matches the case of the string we are checking against, in our case "shop", if it's "Shop", adjust the code, for the sake of simplicity I didn't want to add a filter to adjust the link.title case.
We should be able to merge the elsif lines into one line, however for the sake of readability and clarity I left them as two lines.
Above this line of code
<li class="site-nav--has-dropdown{% if three_level_nav %} site-nav--has-centered-dropdown{% endif %}{% if link.active %} site-nav--active{% endif %}" data-has-dropdowns>
Replace {% if link.active %} site-nav--active{% endif %} in the line above, with {{ link_active_class }}.
Now, it should look like this
<li class="site-nav--has-dropdown{% if three_level_nav %} site-nav--has-centered-dropdown{% endif %} {{ link_active_class }}" data-has-dropdowns>
I didn't test this however in theory it should do the trick!
I want to use {% is.user_authentificated %} to change a function display, but when I add this line, it shows it in the view when I reload the page. Did I do something wrong in it ?
{% if is.user_authentificated %}
li><a ng-if="item.detail_url.indexOf('/layers/') > -1" href="{%
endverbatim %}{% url "new_map" %}?layer={% verbatim %}{{
item.detail_url.substring(8) }}">
{% endverbatim %}
<i class="fa fa-map-marker"></i>{% trans "Create a Map" %}</a>
{% verbatim %}
</li>
{% endif %}
So I resolved the issue. I was placing my tag in a verbatim tag. So I moved it after the {% endverbatim %}and it works.
{% if user.is_authenticated %}
// if user is authenticated then write your code here
{% endif %}
I'm attempting to fix some pagination issues in a Django app. Using the Previous and Next buttons work fine, since I'm using existing variables like previous_page_number, but I'm unsure how to get the Page 1, Page 2, Page N buttons to work. Here's the Previous Page code, which works just fine:
{% if table.page and table.paginator.num_pages > 1 %}
{% block pagination %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
{% block pagination.previous %}
{% if table.page.has_previous %}
Previous
{% else %}
<a href="#" class="pagination-previous" disabled>Previous</a>
{% endif %}
{% endblock pagination.previous %}
And here's my current Pagination Range code, which doesn't. Specifically, the else segment is what I'm unable to get working.
{% block pagination.range %}
{% if table.page.has_previous or table.page.has_next %}
<ul class="pagination-list">
{% for p in table.page|table_page_range:table.paginator %}
{% if table.page.number == p %}
<li>
<a class="pagination-link is-current is-dark" aria-label="Page {{ table.page.number }}" aria-current="page">{{ table.page.number }}</a>
</li>
{% else %}
<li>
{{ p }}
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endblock pagination.range %}
Currently, the pagination doesn't work, and the URL that gets passed ends at page= instead of page=p, whatever p is at the time. I'm uncertain how to pass p in as a readable variable, to cause it to appear in the URL. I've tried using the same format as other parts of the code not in the querystring.
{% else %}
<li>
{{ p }}
</li>
{% endif %}
This causes an error that prevents the page loading at all, as Django can't reconcile the {{ part.
Display
and you can get from the views.py like that;
page = request.GET.get("page", ""),
if it is page is none you can give them default value like this
page = request.GET.get("page", "1")