Handlebars template and BottlePy template (SimpleTemplate) conflicting - handlebars.js

Both template engines use {{ }} tags. I'm trying to serve an HTML file dynamically in BottlePy so that I can dynamically source javascript files, but this HTML file has Handlebars templates all over it. Any ideas on how to get around this? I've heard of this problem with other frameworks (Like Angular and Django) but I'm not sure if the same fix applies here.
Some ideas I've come up with are:
Change the tag of one of the template engines (don't know if you can with these)
Split up the HTML file into multiple parts and dynamically include them (might work but isn't my first choice)
If I could accomplish #1 that would be awesome, but after a bit of googling I'm not sure it's possible. I am open to using a template engine other than SimpleTemplate, so long as bottlepy supports it. #2 sacrifices some loading speed which is the driving force of this whole problem anyway, so I'd rather not do that if possible.
Please let me know if the problem is unclear and I can explain it better. Thanks for your time!

Good question. I haven't found a way to do precisely what you're asking, but a simple (?) alternative might be to use jinja2 (or mako) templates instead of Bottle's SimpleTemplate.
I've used jinja2 for templating with much success, and it looks like it has decent escaping to help you:
http://jinja.pocoo.org/docs/templates/#escaping
(Plus, jinja2 templates have a much richer feature set without much more complexity, so in the long run you might benefit from the switch in other ways.)

Bottle supports jinja, in which you can escape {{

Related

Simple html templating for small sites with grunt

Looking for a simple html templating solution for small sites.
I really want to do some basic includes (similar to some super simple PHP) that generate out to flat html. I had tried using Assemble.io but it seems to contain so much more.
For reference I'm coming from mixture.io which has some really easy templating but since it is a subscription I cant have that be the way our whole office makes sites. I have also seen middleman but I feel like node is just a lot easier to deal with.
I feel like there is a way to do what I'm looking for with mustache alone but my javascript is not very good. Any help would be greatly appreciated.
I'd recommend looking into Cabin
http://colinwren.github.io/Cabin/
Workflow uses Grunt and they added livereload support in the last release. Good alternative to using Jekyll.

Joomla - wrapper | is there any disadvantage?

I'm using Joomla 1.5 and I need to create a simple gallery in my site but I don't want to create new component because it's takes a lot of time to learn...
So I wanted to ask:
if I create a simple jQuery gallery in standalone .html file and then I embed it using Wrapper into Joomla, will there be any heavy problems?
Thanks
You don't need to do a full-blown MVC component for this: a quick one will work. Add the file components/com_jquery_gallery/jquery_gallery.php and add your HTML code there. The HTML will be accessible through index.php?option=com_jquery_gallery.
Joomla Wrapper is essentially an IFRAME. If your gallery works in an IFRAME without any issues, and you're completely happy with updating the embedded HTML file manually, then the only downside is that it is a usability "hack", and it may make it more difficult to manage it in the future.
The wrapper is very limited and you could use a "custom" code plugin instead of the wrapper, which allows you to place html, javascript, PHP into an article, IMO it's better than the wrapper because it gives more control.
I recommend Sourcerer It's great and was updated yesterday :)
Why not just use one of the many free photo gallery extensions??
http://extensions.joomla.org/extensions/photos-a-images/photo-gallery
No code work, plenty of features, and much faster than even the simplest component.

css vs dreamweaver templates

what is the difference in performance between css templates and dreamweaver templates , or are they the same. Need to know which one gets indexed quicker by google.
I want to move my website to one the best templates for quick uploads and ftp linkups with linkmanagement tools
please advise
thanks
This is why I despise Dreamweaver and the alike...
Dreamweaver creates websites, which consist of HTML and CSS code, and maybe some JavaScript.
HTML: the "glue". It's the structure which browsers read.
CSS: the "perty stuff". It's what browsers read to determine how to make your page look (colors, layout, etc.).
Since Dreamweaver makes websites, a Dreamweaver template also helps Dreamweaver to make websites, which implies that it follows the above structure.
Templates just style your site and might provide some basic functionality, so they have nothing to do with uploads. Some might be bloated and cause slow loading times, but that's dependent upon the template.
In the end, Dreamweaver Template is more or less CSS + HTML.
A DW template file helps to isolate parts of your HTML code on a page/page basis. Editable content and "locked" content together (in hopes of making development quicker). If you like DW, and have a template you like - 0use it. But don't expect that to be your silver bullet.
There's no advantage to either template where search engines are concerned (good/bad content withstanding).
Content...(pertinent content) is what Google is after. Having a 1M file of valid content will beat a 200k file of sparse/bait-n-switch content every time (well, it's supposed to, right?).
The answer you are looking for: Every Dreamweaver template is a CSS+HTML template. So it depends on the CSS template you are using. For the most part Dreamweaver is pretty bad about writing optimal CSS and it also uses inline styles which is bad for performance.
The real answer: It is obvious you are a beginner and don't know how silly your question is, it is not even one question, and is open ended and has no answer. There is no such thing as a CSS template, CSS by itself is not enough to create a template and this is just a marketing word to use to sell templates to people looking for such a thing as a better alternative to HTML templates, and etc, there is CSS for a certain type of template or certain Document Object Model, so if that is your definition of a CSS template than every Dreamweaver Template is a CSS template, as Dreamweaver itself is not a web technology or language. Dreamweaver is a WYSIWYG/IDE that helps you to write CSS (and other code) without knowledge of CSS, or in my case I use it because I love the pink/purple syntax highlighting it has for CSS in code view.
*Need to know which one gets indexed quicker by google - FTP Upload - linkmanagement *
This has nothing to do with your question, you can create a website in notepad that gets better SEO results. You are mixing all these different concepts together, SEO, CSS, HTML Templates, google indexing,templates, quick uploads, ftp linkups, linkmanagement tools, these are all different concepts and each require years of experience for you to achieve this. At the end of the day what I am trying to tell you is, building a website as you describe is not a few clicks to create a template with dreamweaver. You first need to learn enough to be able to ask the right questions. And then you will be able to create such a website, not the best and ultimate "templates for quick uploads and ftp linkups with linkmanagement tools" but something that works, even though I'm not sure what exactly you are trying to build.
I Think you should look into a CMS like WordPress and get a nice looking wordpress template for your site and eventually become more familiar with these concepts. WordPress has a really good SEO/(google indexing as you say) that it even gets better results than expensive websites built by professionals. This is definitely what you want! trust me!
http://wordpress.org/

Why is drupal theming so difficult? Any tips for simplifying it or learning it faster?

I've been coding in PHP for 4 years and even I find it so convoluted and hard to grasp. I have no idea how they expect designers to manage theming.
I know basic theming, theming with tpl files, views templates, contemplate templates etc. However I get lost whenever I enter the template.php file.
I needed to theme a node input form for a custom content type. I wracked my brain over it with like 7-9 tutorials and it's still not coming together. I understand why module building can be complicated - because most people who work with modules are developers anyway.
However, when even a developer can't understand theming, it's definitely over-engineered!
Maybe it's my fault, maybe I didn't learn Drupal properly. In that case, is there a step-by-step system to becoming a Drupal guru?
Theme is really not that difficult, if you only know basic php. You have 3 ways of altering the markup, the css and js, you should be able to handle.
Template files. By creating a template file in your theming and naming it correctly, it will take precedence over other template files, and you can thus create custom markup for views, nodes etc. By creating a template for a noce type, you can do stuff like printing out the cck fields in any other instead of using $content. All you need is on the node object.
Preprocess functions, which are placed in your theme, will give you the possibility to add or alter variables that will be used in your template. You name the functions like hooks: yourtheme_page for the page template yourtheme_node for the node template etc. Here you can create some custom logic, or modifications, to help make your templates more clean and just handle the printing of the variables.
Theme functions. You can overwrite theme functions to alter the markup that's used. You only need to create a function called yourtheme_[theme_function_name]. You don't need to understand much php to do this. Often, you can just copy the original theme function, and make a few alterations in it to get the markup you want.
With the above you can do 90-95% of what you need. Forms are a bit special since you in Drupal 6 can't alter them (easily) in your theme. Instead what you want is to create a small module and use hook_form_alter, which allows you to modify the form, text used on buttons etc. This is changed in Drupal 7, which will be even easier to theme.
So it really isn't all that complicated, just use the 3 basic tools described above. The tricky part can be to name your functions and templates, but devel themer can help you with that. Another tool you use is devel which can assist you in printing out variables so you can inspect them and see what you have available, fx CCK fields on the node.
Maybe you should get a copy of Front End Drupal.
In my opinion, Drupal theming is not difficult once you wrap your head around the concepts like templates, overrides, .info files and preprocess functions. Those things are not directly related to php skills, it's all about understanding the system.
It's interesting to see that you're a themer, yet you only talk about php, not CSS and HTML. In my experience, a lot of theming tasks can be accomplished with CSS, without even touching php.
Finally, I don't know if you are using a base/starter theme (like Zen or Genesis) already. I recommend using a base theme and realizing your own design as a sub theme.
Most people get an 'ahah!' moment when themeing suddenly starts to make sense.
I'd argue that this is probably tougher for experienced PHP developers, since you have to get past a lot of concepts that don't make sense in vanilla PHP ("the function is magically called at the appropriate time ... because of how it's named?!")
#googletorp's answers is pretty comprehensive, so I'll just add some practical tips that helped me along:
1) Try building a module that implements it's own themeable output and simple hooks. Hooks and theme functions make a lot more sense when you see how modules are actually calling them and using them.
2) Make liberal use of the devel module, especially the Theme Registry menu (note how it changes when you add a new theme function), the 'Render' tab, and the dpm() and dvm() functions
3) Buy a old-tyme dead-tree book on Drupal themeing. The online docs are really outstanding if you already know what you're doing, but can be extremely confusing if you're not sure what you're looking for.
4) Empty your cup. At the theme level, PHP is really just for simple logic and syntax -- almost everything of substance is getting handled by Drupal API functions. Try to think like a Drupal developer and not a PHP developer (i.e. don't assume you know how to do something just because you built a vanilla PHP site that does the same thing) and you'll have an easier time.
Keep with it! The theme system is actually really easy to use once you've figured it out.
to answer your question on why it is so hard:
Drupal themes may seem overwhelming, due to the sheer amount of possibilities, see #googletorps answer for a good overview.
Having "many ways to do one thing" brings power: power users can choose the best of all possibilities. But it also brings complexity: new users don't get a good lead, because there is no "you should do it this way. fullstop."
Alongside that amount of ways to get stuff done, there is the problem of nesting. Drupal has a concept of very deeply nested items. To take a random, yet simple example:
username<menuitem<menuitem<menuitem<menu<block<region<page.
Will render a menu-item, containing a username in a three level deep menu-item in a sidebar-block.
Where most templating-environments have concepts of a page, containing several "contents" that, at most, might contain some partials. the nesting is at most three levels deep. And each level has a clear, distinct area of expertise. Drupal does not have that: the nesting is fairly arbitrary. And each nested item is no different from its parents. This, again, offers power-users a great concept and power to work with, but is hard to grok for new developers/designers.
Lastly, another reason why it is hard to learn, is that the Drupal online documentation is more a wiki then a read-from-begin-to-end manual. There are great books that fill htat gap, you will have to buy them, though.
If you haven't seen it already, this is a great presentation on why Drupal 6 theming is difficult and how it is improved in Drupal 7. There is hope! The video made more sense to me a second time watching after more experience theming.
http://sf2010.drupal.org/conference/sessions/design-and-theming-whats-new-drupal-7
One of the biggest tricks is to override something that is normal rendered with a theme function into a template. This gives you much more control over the markup, and also lets you use the preprocess functions to manipulate the variables before handing it over to the template.
This is a huge boon to theming forms. See a short video that explains it better than I could here: http://drupaldojo.com/session/fine-tuning-ui-theming-forms-drupal-60

Style a code snippet with css

Could someone give me a link, a tutorial or an already made css template for styling code snippet to add that feature to my blog ?
I seen examples in numerous blogs, but, now that i am searching for one, i can't put hands on it !
I want to be able to post a code snippet with keyword coloration, line numbers etc..
Many thanks in advance.
EDIT : i know there are some solution like prettify (thanks Developer Art) or SyntaxHighliter but i am on a platform and i can't use Javascript
Prettify is what you're looking for.
You include a bunch of JavaScript and CSS files to your pages and mark page sections that need to be prettified. Pretty much it.
manoli.net offers an online copy/paste syntax highlighter:
This tool allows you to format your
C#, VB, HTML, XML, T-SQL or MSH (code
name Monad) code for publishing on a
web site or in a blog.
The output conforms to the HTML 4.01
specification and is color-coded to
make it easier to read. The colors can
be changed by modifying the CSS style
sheet. See a sample.
And you may want to check out the Syntax Highlighter project on CodePlex (not sure how much activity it still has, though):
Syntax highlighter converts code text
to HTML where common language elements
are formatted using style sheet
classes such that the coloring scheme
can be switched or altered as simple
as replacing a CSS file. The primary
release ships as an extension for
BlogEngine.NET.
There are server side solutions for this as well, which of course depend on your server language. PHP is the ever popular choice for blogs, in which case you could use the equally popular GeSHi library.

Resources