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

Tag Helpers: Create an 'environment' Tag Helper #1553

Closed
DamianEdwards opened this issue Nov 13, 2014 · 4 comments
Closed

Tag Helpers: Create an 'environment' Tag Helper #1553

DamianEdwards opened this issue Nov 13, 2014 · 4 comments

Comments

@DamianEdwards
Copy link
Member

A new Tag Helper that utilizes the conditional content mode (aspnet/Razor#221) to only render its contents if the current IHostingEnvironment.EnvironmentName matches the specified name. The target environment names can be specified as a comma separated list via the names attribute (string). In the case of the environment not currently matching, the contents would not even be executed.

Usage

<environment names="">
</environment>

If the names attribute is omitted, the contents are always rendered.

Attributes

Attribute Name Type Details
names string A comma separated list of environment names in which the content should be rendered

Example

<environment names="Development">
    <script src="~/js/file1.js"></script>
    <script src="~/js/file2.js"></script>
</environment>
<environment names="Staging,Production">
    <script src="~/js/site.js"></script>
</environment>
@DamianEdwards DamianEdwards added this to the 6.0.0-beta2 milestone Nov 13, 2014
@yishaigalatzer yishaigalatzer modified the milestones: 6.0.0-rc1, 6.0.0-beta2 Nov 17, 2014
@DamianEdwards DamianEdwards changed the title Create an 'environment' Tag Helper Tag Helpers: Create an 'environment' Tag Helper Dec 11, 2014
@danroth27 danroth27 modified the milestones: 6.0.0-rc1, 6.0.0-beta3 Jan 9, 2015
@Bartmax
Copy link

Bartmax commented Jan 12, 2015

why do you have name and names ? I suggest to keep only with names so one can change from one to multiple only modifying the content.

Also, can this envitorment tag would be anything ? so if we have a model like :

public bool IsValid {get;set;}
public string Name {get;set;}

one my author


<conditional IsValid="true"> .. </conditional>
or
<condition name="Bart, Damian"> ... </condition>

and for the enviroment example:

<condition environment="Production, Staging">...</condition>

or maybe better <if environment="Production, Staging"> ... </if>

@Bartmax
Copy link

Bartmax commented Jan 12, 2015

is there a way to implement fallback environment when the enviroment does not match any of listed names ?
is there a way to implement a NOT condition ? like <environment names="!Staging">

I'm afraid we may see lots of duplicated code... or lots of enviroment clauses. Is the view really the responsable to use one or another ?

@DamianEdwards
Copy link
Member Author

@Bartmax agree on name/names, I'll change that.

You could certainly build a more generic conditional/if tag helper yourself, but we're not planning on doing it. We see environment being something people often conditionally render content on so we're promoting it as a first class tag helper, but fundamentally we don't to go super generic in the tag helpers (and have Razor end up looking like Spark).

DamianEdwards added a commit that referenced this issue Jan 15, 2015
DamianEdwards added a commit that referenced this issue Jan 16, 2015
DamianEdwards added a commit that referenced this issue Jan 16, 2015
DamianEdwards added a commit that referenced this issue Jan 16, 2015
DamianEdwards added a commit that referenced this issue Jan 16, 2015
DamianEdwards added a commit that referenced this issue Jan 16, 2015
DamianEdwards added a commit that referenced this issue Jan 16, 2015
DamianEdwards added a commit that referenced this issue Jan 16, 2015
DamianEdwards added a commit that referenced this issue Jan 17, 2015
DamianEdwards added a commit that referenced this issue Jan 17, 2015
DamianEdwards added a commit that referenced this issue Jan 19, 2015
DamianEdwards added a commit that referenced this issue Jan 19, 2015
@DamianEdwards DamianEdwards self-assigned this Jan 19, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 20, 2015
DamianEdwards added a commit that referenced this issue Jan 21, 2015
DamianEdwards added a commit that referenced this issue Jan 21, 2015
DamianEdwards added a commit that referenced this issue Jan 21, 2015
DamianEdwards added a commit that referenced this issue Jan 21, 2015
DamianEdwards added a commit that referenced this issue Jan 21, 2015
DamianEdwards added a commit that referenced this issue Jan 21, 2015
DamianEdwards added a commit that referenced this issue Jan 21, 2015
DamianEdwards added a commit that referenced this issue Jan 22, 2015
@NTaylorMullen
Copy link

759fbbd

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

No branches or pull requests

5 participants