Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set custom properties on custom template before execute #30

Open
davifiamenghi opened this issue Jan 3, 2014 · 0 comments
Open

Set custom properties on custom template before execute #30

davifiamenghi opened this issue Jan 3, 2014 · 0 comments

Comments

@davifiamenghi
Copy link

I've developed a MvcTemplateBase and MvcTemplateBase and I need to set some properties on those types before execute, like one called ViewData. So I would need to execute the following sequence:

         Type modelType = model.GetType();

        ITemplate template = machine.Context.TemplateFactory.CreateTemplateInstance(viewName, modelType);
        MvcTemplateBase mvcTemplate = (MvcTemplateBase)machine.Context.TemplateFactory.CreateTemplateInstance(viewName);
        ITemplateInternal templateInternal = (ITemplateInternal)template;

        templateInternal.SetModel(model);
        mvcTemplate.ModelTypeForMetadata = new TypeWrapper(metadataModelDefinition, modelType);
        if (viewData == null)
        {
            viewData = new System.Web.Mvc.ViewDataDictionary();
        }

        viewData.Model = model;

        mvcTemplate.SetViewData(viewData);
        mvcTemplate.TempFolder = tempFolder; // custom stuff

        mvcTemplate.Execute();
        templateInternal.Execute();
        machine.ExecuteUrl(viewName, model);

        if (layoutName != null)
            mvcTemplate.Layout = layoutName;

        templateInternal.TryApplyLayout();

One problem I had, is that ITemplateInternal is internal, and I had to make it public to be able to call ITemplateInternal methods.

Let me know if I'm not clear enough or if I can contribute with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant