Toolbelt.Blazor.HeadElement icon indicating copy to clipboard operation
Toolbelt.Blazor.HeadElement copied to clipboard

Provide the ability to set a fixed suffix/prefix for the title

Open aradalvand opened this issue 4 years ago • 2 comments

It happens fairly often where you want the titles across all the pages in your website to have a shared pattern. For instance, no matter what page you're on in Stack Overflow, the title always ends with " - Stack Overflow".

It would be nice if this library provides a feature that allows users to achieve this, it would make it even more superior than it already is to Microsoft's built-in <Title> component.

I propose a property gets added to HeadElementHelperServiceOptions, so that you could do the following:

builder.Services.AddHeadElementHelper(op =>
{
    op.TitleSuffix = " | Tesla Motors";
});

Or something similar. Without this, we currently have to repeat the suffix on every page: (Products.razor)

<Title>Products | Tesla Motors</Title>

That way, this would suffice:

<Title>Products</Title>

Nicer, and cleaner.

There could also be a parameter for the <Title> component with which you can specify not to use the suffix, this is useful when for example you have a page whose title you want to be unique:

<Title UseSuffix="false">Tesla Motors Home Page</Title>

aradalvand avatar Jan 13 '21 17:01 aradalvand

@AradAral

Thank you for your interesting proposal!

However, what you want to do can be implemented without changing this library easily, I think.

I wrote a sample code (Please see the following URL).

  • https://github.com/jsakamoto/Toolbelt.Blazor.HeadElement/commit/bcf1616a84a3cafb9ca58ee2f010a14ed3c8edef

Of course, this proposal is very interesting. I can implement the feature that you suggested.

But I have to consider this suggestion well to keep simplify of this library. Unfortunately, so I have some projects those wait to fix bugs by me, I can not start to consideration or implementation about this suggestion immediately.

Don't forget that you can create your own custom Title component derived from this library, and I'll welcome it.

jsakamoto avatar Jan 15 '21 13:01 jsakamoto

@jsakamoto Hi! Thanks for your response. I get your point, and you're right, I like your demonstration of how it can be done by the developer, I also like the idea of having your custom wrapper component, so I guess I'll probably do it that way. Thank you. Feel free to close this issue if you decide that this is better not implemented as part of the library. I understand your situation. Have a great day!

aradalvand avatar Jan 15 '21 13:01 aradalvand