-
- 388 Posts
Hello I would like to know how can I use a Template Tag for example [[*pagetitle]] or a setting value [[++setting]] as default value in a Template Variable?
The TV is an Input Type: Text
The idea is have the TV input fields in the manager already filled with Template Tags values, the user will decide if use the default value or edit it, right now is showing the [[*TemplateTag]] format but not the real value.
Thank you very much.
--
ysanmiguel.com
-
- 932 Posts
Edit the template variable and under input options you can enter a default value. Just put your [[*pagetitle]] tag in there.
-
- 571 Posts
I think that is what I would expect to see in the Manager.
But if you then call that template variable into your public facing content on a web page (not in the manager) it should process the TV and display the actual page title.
-
- 5,888 Posts
can't you just do something like that in your template:
[[*yourTV:default=`[[*pagetitle]]`]]
and give a hint in the TV - description, that the pagetitle is used, as long, as the TV is empty?
If you really want to show the parsed value of a tag, you will need to create a custom-TV-input-type, which parses the default-value before showing the manager-form. Its not that difficult.
-
- 1,145 Posts
Solution 1. use MODX things to parse your tags
https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/eval-binding
https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/bindings/chunk-binding
If this gives silly issues, move on to #2
Solution 2. Use a tiny plugin
The plugin on OnDocFormRender, will check if the TV input field is empty. (note, this is not a TRUE default TV value)
But f you have the TV reset button then it is true DOM default value
If empty, fill it up with the pagetitle of current resource (if current resource is not a New one)
<?php
$tvId = 20;
$defaultTVvalue = "";
//Alter Resource TV default/value
//Plugin fires at OnDocFormRender
// if($mode == "upd"){
if($resource){
$defaultTVvalue = $resource->get("pagetitle");
}
$modx->regClientStartupHTMLBlock('
<script>
Ext.onReady(function() {
// var tv = document.getElementById("tv'.$tvId.'");
var tv = Ext.get("tv'.$tvId.'");
var tvDef = Ext.get("tvdef'.$tvId.'");
//Note upon save, this tv will have a real value in Database
if(tv){
tvValue = tv.dom.value;
tv.dom.value = tvValue || "'.$defaultTVvalue.'";
}
//If you have that squiggly thing for TV refresh, the value will be set
if(tvDef){
tvDefValue = tvDef.dom.value;
tvDef.dom.value = tvDefValue || "'.$defaultTVvalue.'";
}
});
</script>
');
TinymceWrapper: Complete back/frontend content solution.
Harden your MODX site by
passwording your three main folders:
core, manager, connectors and renaming your
assets (thank me later!)
5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
-
- 1,145 Posts
If for 20+ TVs, just do a tiny loop, done!
TinymceWrapper: Complete back/frontend content solution.
Harden your MODX site by
passwording your three main folders:
core, manager, connectors and renaming your
assets (thank me later!)
5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.