Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Consider adding HTML templates #1898

Closed
JeanCollas opened this issue Jan 2, 2018 · 7 comments
Closed

Consider adding HTML templates #1898

JeanCollas opened this issue Jan 2, 2018 · 7 comments

Comments

@JeanCollas
Copy link

JeanCollas commented Jan 2, 2018

Would adding custom local HTML templates not be a good option to consider?
Something similar to the following would be an option for the implementation:


@functions{
    IHtmlContent DispItem(string id, string name, string description)
    {
        <li>
            <a href="/manage/@id">@name</a>
            <span>@description</span>
        </li>
    }
}
...
<ul id="list1">
    @foreach(var item in items1)
    {
        DispItem(item.Id, item.Name, item.Description)
    }
</ul>

<ul id="list2">
    @foreach(var item in items2)
    {
        DispItem(item.Id, item.Name, item.Description)
    }
</ul>


Creating a separate file and model for this kind of display is sometimes too much as compared as what it intends to do.
Simplifying this by allowing local templates would be helpful.

Except if I missed it, it is not possible at this time (except by using html strings concat or external sub-pages/components).

@mkArtakMSFT
Copy link
Member

Looks like we have a similar issue we're considering: https://github.com/aspnet/Razor/issues/821

@mkArtakMSFT
Copy link
Member

/cc: @DamianEdwards

@JeanCollas
Copy link
Author

@rynowak
Copy link
Member

rynowak commented Jan 5, 2018

@NTaylorMullen - do we have a doc about the existing support for templates in Razor? I looked at https://docs.microsoft.com/en-us/aspnet/core/mvc/views/razor and couldn't find anything about templates.

@JeanCollas - We have an existing feature that's somewhat limited. #821 tracks some improvements we want to make, but that won't be part of this release.

Example:

@{
    Func<dynamic, object> foo = @<text>This works @item!</text>;
    @foo("")
}

More examples from our tests: https://github.com/aspnet/Razor/blob/dev/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Templates.cshtml

@rynowak rynowak reopened this Jan 5, 2018
@rynowak rynowak added this to the Discussions milestone Jan 5, 2018
@NTaylorMullen
Copy link

do we have a doc about the existing support for templates in Razor?

We don't have an official doc. However, we do have some ad-hoc conversations that have some great template examples given the APIs that are available today: #281

@RandyBuchholz
Copy link

This proposal - Design-Time Directive [Language Feature Proposal] #1747 - might be relevant here. It addresses an approach to templating.

@aspnet-hello
Copy link

We periodically close 'discussion' issues that have not been updated in a long period of time.

We apologize if this causes any inconvenience. We ask that if you are still encountering an issue, please log a new issue with updated information and we will investigate.

@aspnet-hello aspnet-hello removed this from the Discussions milestone Sep 24, 2018
@aspnet aspnet locked and limited conversation to collaborators Sep 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants