How do I dynamically assign a TV to a document container through a snippet?
I’m not entirely sure what it is you want to do. I you by document container mean placeholder something like this (not tested):
<?php
$tv = $modx->getTemplateVarOutput('myTemplateVar');
$modx->setPlaceholder('mytvplaceholder',$tv);
?>
And then place a [+mytvplaceholder+] in your content/template. But [*myTemplateVar*] would give the same result in this case, so it’s pointless if you don’t do anything else in the snippet.
If the above doesn’t answer your question, you need to provide som more info...
MODx snippet-glossary 101:
Ditto = Content Lister -- Wayfinder == Menu Builder -- Jot = Comment Control
You can also create the TV and give it a default value of @eval $modx->runSnippet(’MySnippet’); .
That way any value returned by MySnippet will be assigned to the TV for the current page.
<?php
// MySnippet
$output = "somevalue";
return $output;
?>
In theory, you could create a TV from inside a snippet, give it a value, attach it to a template, and assign it to one or more documents but it would involve a substantial amount of direct manipulation of the MODx database. There’s almost certainly an easier way to accomplish what you’re trying to do. If you describe what you’re attempting yo do (and why), someone might be able to suggest and easier alternative that would accomplish the same goal.
Hope this helps.
-
☆ A M B ☆
- 24,524 Posts
You can’t. Why do you want to do this?
I would like to create a simple snippet to upload pdf files
<vent>
the default uploader has failed me. I did everything from permissions to URL and other paths but it has been two weeks and its the only thing left to get to work.
so I thought it best to program it instead of waiting for a solution. I am about to lose the client, so I think coding it in a few days would save my reputation.
if it cannot be done, and I find no alternative, for this project, I may have to resort to a different solution. though I WILL NOT abandon MODx. love it, esp being a programer... but its sometimes thoroughly frustrating. we will grow with it.
</vent>
Is there an existing snippet that can offer an alternative similar to a File TV that is simple and straightforward?
-
☆ A M B ☆
- 24,524 Posts
This is so manager users can upload .pdf files? Have you checked the manager user’s individual configurations to make sure they can upload .pdf files (or the "use system configuration" boxes are checked)?