Basically, what I'm trying to do is get a 1/4 of a price in a Django Template Editor.
quote.total is a generated value by the system, for example: 1235.00, and I need to manipulate that value to show 308.75 (1235.00 divided by 4).
I've tried things like using {% widthratio quote.total 4 1 %} to get the quotient, however widthratio rounds the quotient, and I need an exact one.
I've also tried {% widthratio quote.total 4 100 %}, to get the quotient multiplied by 100 (implying that all I'd need to do is figure out how to place a decimal point two places over), but have found no way of using CSS to place a decimal point in.
It is also worth noting that because of the products I am working with quote.total will never have a value in the tenths or hundreths place. I've tried using that to my advantage by adding modulus operators and complex math rules & logic with no success.
The one problem with the system I am using is I have no access to the backend to create custom functions, and because of the way the system parses the template, I cannot use script tags.
EDIT: I see you cannot use tags since you have no access to the back end. You may need a JS-based solution. I'll leave this answer up in case it helps someone.
This is a pretty common use case. Consider using a custom filter, something like:
template.html
{% load quarter %}
{{quote.total|quarter}}
/your_app/templatetags/quarter.py
from django import template
register = template.Library()
#register.filter()
def quarter(value):
return (float(value) * 0.25)
Documentation on custom filters is here in the Django Docs. Also, as with any template tag, be sure to restart your server after adding it, or it will django will not register the tag and will throw an error. This is true of production and development servers.
Related
TLDR - how do I use either a custom parser function or modify the loop module to it'll add a newline after each iteration?
Long story:
I'm using old templates that used to be rendered with some MS tools, now trying to render them with docxtemplater. Main requirement is to not modify the templates. Use them as they are, and be able to render documents as identical as possible to that MS tool.
Here's what a loop looks like in one of the templates:
«TableStart:MortgageInfo»« MortgageInfo_Name»
« MortgageInfo_MortgageStreet»
«CityStateZip»«TableEnd:MortgageInfo»
I used custom delimiters for « and » and created a custom loop module to handle the custom TableStart: and TableEnd: format.
There is no linebreak between «CityStateZip» and «TableEnd:MortgageInfo» so the 2nd item is rendered immediately after the 1st without a linebreak.
Anybody has any idea how I add this missing linebreak? Please bare in mind - no modification to the template is allowed...
I'm using Prestashop 1.6
In order-carrier.tpl, I'm trying to get the carrier id, because I would like to use it in the css class of the <div>.
For exemple : div.delivery_option.carrier_id_33
I tried this :
{$cart->id_carrier}
But it doesn't really work.
If it's in TPL file, you need to use getcontext() first
So in this case it would be
{context::getContext()->cart->id_carrier}
Late answer here, but I write mainly for future reference.
First, there should always be a global $carrier smarty variable available to templates. Just check placing a {debug} tag on the place you want to use it and see if it's there.
Second, DO NOT use id_carrier. It's quite strange but you will loose it. It's not a really reliable property. I discussed the issue with the developers some time ago. You should use id_reference instead: that won't change.
http://forge.prestashop.com/browse/PSCSX-4651
So, to sum up:
{assign var=carrier_instance value=$carrier.instance}
{* then later somewhere: *}
{$carrier_instance->id_reference}
this will do the job.
Try this code
<div class="delivery_option {if ($option#index % 2)}alternate_{/if}item {foreach $option.carrier_list as $carrier}carrier_id_{$carrier.instance->id}{/foreach}">
The carriers are not directly accessible, but they are encapsuled inside the variable $option
Since I always get here whenever I search for id_reference from smarty I'll post my solution for 1.7
{$carrier_id = context::getContext()->cart->id_carrier.id_reference}
Returns the carrier_id_reference, the nice one cause carrier_id changes everytime you modify a carrier, so the real ID you need in order to operate with carriers is id_reference
In particular, the case I have in mind is this:
##RenderComponentPresentation(Component, "<vbs-legacy-ct-tcm-uri>")##
The problem I'm having is that in my case VBS code breaks when it tries to access component fields, giving "Error 13 Type mismatch ..".
(So, if I were to give the answer, I'd say: "Partially, of no practical use")
EDIT
The DWT above is from another CT, so effectively it's a rendering of component link, that's why parameterless overload as per Nuno's suggestion won't work unfortunately. BTW, the following lines inside VBS don't break and give correct values:
WriteOut Component.ID
WriteOut Component.Schema.Title
EDIT 2
Dominic was absolutely wright: it's a missing dependencies.
A bit more insight to make this info generally useful:
Suppose, the original CT looked like this ("VBScript [Legacy]" type):
[%
Call RenderComponent(Component)
%]
This CT was meant to be called from a PT, also VBS-based. That PT had a big chunk of "#include" statements in the beginning.
Now the story changes: the same CT is being called from another, DWT-based, CT. Obviously (thanks you all for your invaluable help!), dependencies are now not being included anywhere.
The solution to make original CT working again is to explicitly hand-pick and include all necessary VBS TBBs, so the original CT becomes:
[%
#include "tcm:<uri-of-vbs-tbb>"
Call RenderComponent(Component)
%]
Yes - it's perfectly possible to mix and match legacy and modular templates. Perhaps obviously, you can't mix and match template building blocks between the two techniques.
In VBScript "Error 13 Type mismatch" is sometimes used as a secret code that really means "I don't recognise the name of one of your variables, (including the names of Functions and Subs)" In the VBScript templating engine, variables from the page template could be in scope in your component template; it was very common, for example, to put the #includes in the PT so they could be used by the CT. My guess is that your component template is trying to use such a Function, and not finding it.
I know that you can render a Modular Page Template with VBScript Component Presentations, and also a VbScript page template can render a modular Component Template.
Your error is possibly due to something else? Have you tried just using the regular ##RenderComponentPresentation()## call without specifying which template?
The Page Template can render Compound Templates of different flavors - for example Razor, VBS, or XSLT.
The problem comes from the TBBs included in the Templates. Often the Razor templates will need to call functions that only exist in VBScript. So, the starting point when migrating templates is always to start with the helper functions and utility libraries. Then migrate the most generic PT / CT you have to the new format (Razor, XSLT, DWT, etc). This provides a nice basis to migrate the rest of the Templates as you have time to the new format.
I would like to restrict the fields while creating a new post in WordPress. For the title, it should not exceed 40 characters. For the content, it should not exceed 400 characters. If these maximum values are exceeded, I would like to show an error message and not let the user continue. How do I do that in WordPress?
You should be able to use wordpress filters to modify the code that gets outputted when the editor is called. Essentially you would want to use it to insert some javascript and an extra div tag to display your error, then just read the contents of the "editorcontainer" id and show the error once it reaches a certain character limit.
I don't have the time at the moment to write a case example, but depending on your skill level, the functions you are looking for are:
apply_filters("the_editor", "customfunction_limitarea");
Where customfunction_limit area is your created function to insert the javascript. You can see how the_editor is currently called and how the default filters are applied in "wp-includes\general-template.php" on line 1822. The default looks like this:
$the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
I would try modifying that statement by placing a new filter in a functions.php file located in your themes directory, that way you don't have to worry about it getting over-written during an update. Otherwise, if you absolutely have to edit the wordpress core (generally a no-no), general_template.php would be the place to do it I think.
Essentially just read up on wordpress filters a little bit (be warned there's not a ton of documentation or examples available for it other than the basic stuff), and that should provide everything you need. The input verification end is easy enough to find scripts, just google jquery post limiting. Something like this might be exactly what your looking for:
http://swiki.fromdev.com/2010/02/jquery-maximum-limit-texttextarea-with.html
How do you change the QTY (quantity) label in UberCart (in Drupal) without actually hacking the core components? I want the label to be be months, instead of qty.
You could use the String Overrides module. Here is an excerpt from its project page:
Provides a quick and easy way to replace any text on the site.
Features:
Easily replace anything that's passed through t()
Locale support, allowing you to override strings in any language
Ability to import/export *.po files, for easy migration from the Locale module
Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
I once ran into a similar issue with Ubercart in another language (German), and we "solved" it by re-translating the string. The mentioned module should do the trick in your case.
I haven't used ubercarts, but I would guess there would be an admin section to do that. Else hook_form_alter() or hook_form_FORM_ID_alter() should be able to do the trick for you.
Unfortunately, there is no setting for this in ubercart.
Doing a search for 'Qty' (case sensitive, as there are numerous 'qty' in code) in the current ubercart-6.x-2.0-rc7 release gives seven matches:
3 in theme functions, which you'd need to override in your theme
1 in a form definition, which you'd need to change via hook_form_alter as googletorp suggested
3 in table definitions, which you'd need to change via hook_tapir_table_alter and/or hook_tapir_table_header_alter (see the hooks.php file in ubercarts doc directory for these)
So you should be able to implement your changes without changing the module itself, but given the amount of work involved, I'd try schnecks suggestion first ;)