I want to have a block oh html across all my templates (like a sidebar for basic form submissions), which is easily implemented on the html files by using blocks.
However, my doubt is not about the repetitions across templates, but across views. Since the functionality will be the same across all templates, it would be really boring (and bad programming) to define the request handling (that would come from that side bar's submissions) for every view I have! How should I handle this? Should (and can) I make a view dedicated to handling that "all-around" part of the template?
Any advices are welcome,
Thanks in advance
Daniel is refering to an Inclusion Tag
Basically, a custom template tag is used for scenarios like yours (... code reusability amongs many other advantages)
Also this post might be helpful: Django Custom Inclusion Tags
Another approach could be using template inheritance - create a base template, which defines the layout, and override the blocks of code that would change for specific views.
Here is an example of template inheritance: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
Use a custom template tag - probably an inclusion tag.
Related
I want to know if there is a way to create a form that will keep all styles of a webpage, while changing the content of the content of the page. Ex: When you submit a question to Stackoverflow, it keeps the all stylistic parts of the page, i.e. Header and sidebars, while changing the title and majority of page's content. Also if you can would a server-side languange, such as php, be best or would a web-side languange, such as Javascript, be best
You can do this by css also you can devide the page into many files
such as putting the header in another page (header.html) and include it in the main page using php (include_once('header.html'))
Style sheets (CSS) exist for exactly this task. Ideally, the HTML for a page contains only its content, while style sheets contain all presentation (the "look"/"format" of the page). Reusing the same style sheet(s) on most or all pages results in a consistent look across an entire website.
See http://www.w3schools.com/css/ for more general information and tutorials.
Edit If you're referring more to reusing "structural" markup across pages, that is accomplished using a template engine. Using templates things like primary navigation, sidebars, etc. can be defined in one file and used on any page that extends the base template. Many web frameworks have a template engine built-in (Django, for example has one I personally use and like).
This is handled using CSS. Basically, websites are built using HTML, CSS, and JavaScript.
HTML builds the structure of the website. It creates the basic building blocks of the site.
CSS takes care of how the website looks. It stylizes the building blocks.
JavaScript takes care of the functionality of the website. It can manipulate the building blocks in order to make something happen.
In order to maintain the same look of certain elements on a website, it is best to create a so called pattern library. A pattern library is a document consisting of pieces of code—these pieces can be reused throughout the website in order to maintain consistence. In this document, you specify the formatting of the essential elements (headings, body text, blockquotes, buttons, form elements etc. (Pattern libraries are sometimes also referred to as "style guides", however, style guides are usually visual documents, while pattern libraries are consisting of pieces of code.)
Of course you can specify the look of your website without using a pattern library, however, it might get a bit harder to maintain the same style throughout the whole website or keep the styling the same when handing the project over to another developer.
You can read more about pattern libraries in this post if you feel like it.
When webpage layout is repeated throughout website, what do you use to escape repeating the code? (analogous to rails html layouts with their yield).
I guess I just can't properly form a google request, there must be something widespread.
There's a bunch of systems for this. I personally use Jinja2, although there are many different frameworks. In general these are called Templating Systems, and they go through your HTML and respond to commands to generate text.
I have a html template that has multiple pages like home, about us,contact,services,... and I want to convert it to a joomla template.I spent a lot of time for searching a good tutorial in google like this:
http://www.learning.asarayan.com/education-website-design/joomla-training2/334-convert-html-to-joomla-template
but non of them can answer my question: how can I convert ALL pages of html to joomla??I mean that I can convert one page for example home to joomla and define its position but what about other pages?
can anybody introduce me a COMPLETE tutorial???
sorry for my poor english
thanQ
You may start with tutorial posted at below address
http://www.tobacamp.com/tutorial/5-easy-steps-converting-html-template-to-joomla-template/
There is no automatic converter or out of the box solution for this, neither any tutorial to help you.
The best way to sort out the issue is by duplicating the template with the help of Artisteer. You can just recreate the template design and feel with Artisteer. Download link: www.artisteer.com/?p=downloads
You need to change your mindset from that for a static template to that for a dynamic template.
In joomla templates there is a base layout called index.php as you know. But that is very skeletal usually, is just defines some locations on a page, includes your css and javascript that is common to all of your pages. This gives your site a common look and feel and ensures a good user experience.
For your css for the individual pages you would normally just include that in the template.css file or similar.
Within the index file you will see places that say jdoc:inlcude. These are the places that actually include the layouts that provide detailed html for specific blocks on the page, typically there will be one component jdoc (there cannot be more than one) and many modules and module ones as well as some others.
The html for these documents is found in the components/com_componentname/view/viewname/tmpl folders.
To override the core layouts you use the template override system by placing same named files in the html folder of your template. You can look at the included templates to see how this works. There is pretty good documentation of this on the joomla documentation site.
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core will get you started.
Also this may be a point of confusion. In a CMS you strive to separate content from presentation. So if you enter the core information in the cms, i.e enter the contact information in com_contact, and enter most of your current content into individual articles you will start to see how it actually works. I would usually recommend first entering all of your static content into the appropriate places, then work on making the rendered pages look exactly the way you want them to.
I am converting mockups to HTML + CSS. Then this will be used as a template for a PHP system by other people (actually it can be any server side language, PHP is not important)
There are, for example, 10 different type of pages. But in each page, many blocks can differ in many cases. For example a block can be displayed differently for anonymous and logged in users. But I dont want to copy the whole html file and just change that block and have another html file. I know php can be written to include parts of the page from many files. But there is no php yet in my design workflow, and I want to have full HTML design before ever passing the files to PHP guys.
Basically, what I want is a "CASCADED" html structure for design purposes. So in a "container" html file, I can include all the different parts from different HTML files.
Does anyone know a method / tool / process to design dynamic pages?
I can think of two ways of accomplishing this. First pull in each of the various components on the page with ajax calls, jquery will make this relatively easy.
Or if you don't want to use javascript then iframes. But the iframes method is extremely prone to buggyness and in some layouts just will not work. Also keep in mind that since you aren't directly injecting html into the page each page would have to keep track of its own styles.
Does Django have any template tags to generate common HTML markup? For example, I know that I can get a url using
{% url mapper.views.foo %}
But that only gives me the URL and not the HTML code to create the link. Does Django have anything similar to Rails' link_to helper? I found django-helpers but since this is a common thing I thought Django would have something built-in.
No it doesn't.
James Bennett answered a similar question a while back, regarding Rails' built-in JavaScript helpers.
It's really unlikely that Django will ever have 'helper' functionality built-in. The reason, if I understand correctly, has to do with Django's core philosophy of keeping things loosely coupled. Having that kind of helper functionality built-in leads to coupling Django with a specific JavaScript library or (in your case) html document type.
EG. What happens if/when HTML 5 is finally implemented and Django is generating HTML 4 or XHTML markup?
Having said that, Django's template framework is really flexible, and it wouldn't be terribly difficult to write your own tags/filters that did what you wanted. I'm mostly a designer myself, and I've been able to put together a couple custom tags that worked like a charm.
The purpose of helpers is not, as others here imply, to help developers who don't know how to write HTML. The purpose is to encapsulate common functionality -- so you don't need to write the same thing a thousand times -- and to provide a single place to edit common HTML used throughout your app.
It's the same reason templates and SSI are useful -- not because people don't know how to write the HTML in their headers and footers, but sometimes you want to write it just once.
EG. What happens if/when HTML 5 is
finally implemented and Django is
generating HTML 4 or XHTML markup?
Same thing that happens when HTML 5 is implemented and all your templates are written in repetitive HTML, except a lot easier.
The other posts have already answered the question, linking to the docs on custom template tags; you can use tags and filters to build your own, but no, there aren't any built in.
it doesnt look like they're built in but here's a couple snippets. it looks like it'd be pretty easy to create these helpers:
http://www.djangosnippets.org/snippets/441/
Here is a list of all template tags and filters built into Django. Django core doesn't have as much HTML helpers as Rails, because Django contributors assumed that web developer knows HTML very well. As stated by saturdaypalace, it's very unlikely for AJAX helpers to be added to Django, because it would lead to coupling Django with a specific JavaScript library.
It's very easy to write your own template tags in Django (often you need just to define one function, similiar to Rails). You could reimplement most of Rails helpers in Django during a day or two.
I bet if there would be any consent of what is common html, there would be helpers module too, just for completeness (or because others have it). ;)
Other than that, Django template system is made mostly for HTML people, who already know how to write p, img and a tags and do not need any helpers for that. On the other side there are Python developers, who write code and do not care if the variable they put in context is enclosed by div or by span (perfect example of separation of concerns paradigm). If you need to have these two worlds to be joined, you have do to it by yourself (or look for other's code).
This won't answer directly to the question, but why not using foo in template then?