Go Template - calling another template with multiple parameters - go

I'm using an application that is getting me some data, and then renders a config file based on a given Go Template. You basically pass a template you've made as a parameter, and app does it's job with it. The template is getting bigger and bigger, so I wanted to wrap some common stuff into sub-templates (I mean, {{ define x }}). The problem I'm occuring is that the sub-template should be passed serveral parameters, which are not a part of my 'dot', and I can't really find a way to do this in Go.
The best answer I've found is to write some 'dict' function myself, and then use it inside the template, but that would mean I basically need to fork the whole application I'm using to render the template, do like 10-15 line changes, and then use this modified versions, which is a nonsense.
I'm wondering if there's any real solution for my problem without having to do some crazy forking and writing custom methods on application side?
Edit:
I've already checked Calling a template with several pipeline parameters before, although it's not answering my question, since I need a way to do this using only template file.

Related

SoapUI (non pro) Property Transfer getting the basics going using XPath

Preamble: First off - I am a complete novice, and have zero clue what I am doing, apologies in advance.
Question:
I have working SOAP messages in SoapUI (regular flavour) that I have valid responses to. I am trying to build a set of test steps that can complete a transaction lifecycle for testing.
I only just figured out that Property Transfer could be used to take a response from call A to be used in call B.
I have the source declared correctly, and the Target correctly, With the default namespace info I have successfully transferred the complete response of call A into the target property. Now I just need to cut that down to one element only. I have tried all manner of things, but I seem to be getting [null] every time (except where I don't include the bit to choose one element at all, as noted above).
I just don't know what the format of the line that specifies the desired field should be. I know I have to have the name of the desired field in it, near the end, but beyond that I am randomly trying all sorts.
Okay, I have it solved, after many stupid trials and errors. For posterity and so I can reference it myself in future, this is what I got going:
Inside the soap message response body, there is a tag ns1 (which I am guessing is namespace 1).
Inside that is a section called salesInvoiceReturn.
Inside that is another section called salesInvoiceDetails.
Inside that is a field that I need is called salesInvoiceSalesTax.
So my line in the XPath Source section that works reads:
//ns1:salesInvoiceReturn/salesInvoiceDetails/salesInvoiceSalesTax
Pressing the Run button shows me it captures the correct value into the Custom Property I selected. I don't seem to need any code at all in the Target section.

MiniProfilerEF view results without RenderIncludes()

Is there another way to view the profiling results of MiniProfiler (I'm specifically interested in EF5 version)?
Every tutorial that I've seen uses MiniProfiler.RenderIncludes(); but since my MVC app mostly returns JSON, that is not an option for me.
Is there a way to write results to file or something like that?
You can read and write results to just about anywhere by changing the MiniProfiler.Settings.Storage to a different IStorage implementation from the default (which stores to http cache). If you wanted to, this could store to and read from a file pretty easily (you would have to write your own custom implementation for that).
The files served by RenderIncludes are the html templates for displaying the results and the script to retrieve the results from the server and render them on the client (all found here). But you are by no means obliged to use this mechanism. If you want to write your own logic for retrieving and displaying results, you should base this off of the logic found in MiniProfilerHandler.GetSingleProfilerResult. This function roughly performs the following (putting in the siginificant steps for your purposes):
Gets Id of next results to retrieve (through MiniProfiler.Settings.Storage.List())
Retrieves the actual results (MiniProfiler.Settings.Storage.Load(id))
Marks the results as viewed so that they wont be retrieved again (MiniProfiler.Settings.Storage.SetViewed(user, id))
Converts these to ResultsJson and returns it
With access to MiniProfiler.Settings.Storage, you should be able to retrieve, serve and consume the profile results in any way that you want. And if you are interested in using the RenderIncludes engine but want to mess around with the html/js being served, you can provide your own custom ui templates that will replace the default behavior.

Caching with codeigniter and twig

I'm trying to cache my output. I'm using Codeigniter's built-in feature $this->output->cache() but it doesn't work. My guess is because I'm using twig. Any ideas?
I found the answer, may it be useful for whoever pass here.
$output = $this->twig->render('template.html'); // use render instead of display
$this->output->set_output($output); // use CI's output (autoloaded by default) manually
$this->output->cache(5); // cache for 5 minutes, doesn't matter where this line is in the function.
As you discovered yourself, you should map output to the Output class via one of the appropriate methods in order to take advantage of its built-in caching features. Note that CI 3.0 currently in development on Github has some updates that you may like (gzipped cache files that retain all output headers, for example).
You could extend the Loader library with a customized view() method, and perform the logic there as well, rather than needing 2+ lines in each controller (if you wanted to load multiple files, you'd have to call render() then append_output() every time).
I did exactly that with the Smarty template library. Should be able to do something similar with Twig. (I've been meaning to port it over as well, but haven't had the time.)

How do I use continuations in FubuMVC

https://github.com/adymitruk/fubumvc/commit/083e1d593d4e797ac04fb493acd1e29a332cd303?w=1
It seems returning a continuation breaks the binding to the view. It used to work before I added the continuation. Now I get a blank page for the default view.
You're using the same input model for your get and your post, so when you transfer, you get into an endless loop. I'm surprised you don't get a stackoverflow. There must be some checking in FubuContinuation that breaks the loop.
You're using the input model as the view model which you (generally) shouldn't do.
Your form tag needs to be a
Also, it looks like due to the naming of your models and the folders, the default view conventions weren't matching up views to your actions. To get things working, I threw them all in the same folder (bad, I know).
You'll want to sort out the folders and namespaces before doing anything serious with this.
Here's the pull request which I was able to get working and posting and such:
https://github.com/adymitruk/fubumvc/pull/1

Is There A Downside To Calling Models From Helpers In CakePHP?

A bit of context: I need to cache the homepage of my CakePHP site - apart from one small part, which displays events local to the user based on their IP address.
You can obviously use the <cake:nocache> tag to dictate a part of the page that shouldn't be cached; but you can't surround a controller-set variable with these tags to make it dynamic. Once a page is cached, that's it for the controller action, as far as I know.
What you can usefully surround with the nocache tags are elements and helpers. As such, I've created an element inside these tags, which calls a helper function to access the model and get the appropriate data. To get at the model from the helper I'm using:
$this->Modelname =& ClassRegistry::init("Modelname");
This seems to me, however, to be a kind of iffy way of doing things, both in terms of CakePHP and general MVC principles. So my question is, is this an appropriate way of getting what I want to do done, or should it ring warning bells? Is there a much better way of achieving my objectives that I'm just missing here?
Rather than using a Helper, try to put your code in an element and use requestAction inside of the element.
see this link
http://bakery.cakephp.org/articles/gwoo/2007/04/12/creating-reusable-elements-with-requestaction
This would be a much better approach than trying to use a model in your helper.
Other than breaking all the carefully-laid principles of MVC?
In addition to putting this item into an element, why not fetch it with a trivial bit of ajax?
Put the call in its own controller action, such that the destination URL -> /controller/action (quite convenient!)
Pass the IP back to that action for use in the find call
Set the ajax update callback to target within the element with the results of the call accordingly
No need to muck around calling Models directly from Views, and no need to bog things down with requestAction. :)
HTH

Resources