Theming language in shopify
how can i create my own themeing tags/language or whatever its called like shopify is using? smarty has it also, sorry i dont know what its called.
for example in shopify if you type
<h1> {{ product.title }} </h1>
- this will print out the products title. what im wondering is how can i create my own langu开发者_如何学Pythonage of this type using php?
Shopify's templating engine is called Liquid, and Smarty is itself a templating engine. Use one of these in your app - don't bother implementing your own.
The basic way that they work is you pass them a template file, and a map of variables (such as the "product" variable in your example), and these are exposed as objects you can reference in the template.
It's called a template language. PHP pretty much is a template language, since you can embed PHP code and drop variables into HTML.
People usually have *.tpl
files in PHP which they designate as templates, and they're usually kept free of logic-heavy code, so that it looks more like the code you referenced above.
how can i create my own themeing tags/language or whatever its called like shopify is using?
Have a look at:
- How to make a simple HTML template engine in PHP
- Writing a Template System in PHP
I'm guessing here: being able to call product.title is most likely not a feature of the tempalte engine but of your object model (if any). I guess product.title calls the method / field on the object, which returns the title.
精彩评论