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

Template instantiation not yet supported on the server side #171

Closed
amieres opened this Issue Apr 18, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@amieres
Copy link

amieres commented Apr 18, 2018

Two things

  • Login is not working on the WebSharper.com site.
    A big dialog that says "Login wasn't successful" keeps popping up no matter what option is selected.

  • I'm trying to use Templates with the FromDocument option on the client with a page served by the server that includes the templates. The idea is to be able to change the file and refresh the browser to see the changes but I get the exception Template instantiation not yet supported on the server side

How can I serve a page that includes Remoting functions and server content with templates that can be modified without recompiling?

@granicz

This comment has been minimized.

Copy link
Member

granicz commented Apr 18, 2018

Can you retry logging in with your cache cleared?

@amieres

This comment has been minimized.

Copy link
Author

amieres commented Apr 18, 2018

Thank you, that worked.

Any idea on point 2?

@Tarmil

This comment has been minimized.

Copy link
Member

Tarmil commented Apr 18, 2018

What this error message means by "Template instantiation" is the feature where you instantiate a subtemplate directly in the HTML file using a <ws-MyTemplate> tag. That is indeed currently only supported on the client side. Even though in your case these are indeed intended to be used on the client side, the server side is still confused by these <ws-*> tags. That's definitely something we need to improve.

Your workaround for now is to instead instantiate these in F# (which I know is far from ideal). For example if you have something like this:

<div ws-template="MyTpl">${Content}</div>
<ws-MyTpl>
  <Content>Hello world!</Content>
</ws-MyTpl>
Template()
    .Doc()

Then you need to do something like this:

<div ws-template="MyTpl">${Content}</div>
<div ws-replace="MyTplHole"></div>
Template()
    .MyTplHole(Template.MyTpl().Content("Hello world!").Doc())
    .Doc()
@amieres

This comment has been minimized.

Copy link
Author

amieres commented Apr 18, 2018

Thanks for the help.
In the end I placed the templates in a separate file which I reference for compilation and when serving the page I read the file and inject the code into the page using Verbatim:

    let content (ctx:Context<EndPoint>) (endpoint:EndPoint) : Async<Content<EndPoint>> =
        Content.Page(Title = "Main Page" 
                   , Body = [
                       Html.client <@  main() |> renderDoc @> 
                       Doc.Verbatim (System.IO.File.ReadAllText TemplatesFileName)
                     ])

It works very well! I can refresh without having to recompile.

@Tarmil

This comment has been minimized.

Copy link
Member

Tarmil commented Apr 26, 2018

Hi, I just pushed a fix for this. In UI 4.2.6 you'll be able to use client-side <ws-*> instantiation with a server-side rendered with Template().Doc().

@Tarmil

This comment has been minimized.

Copy link
Member

Tarmil commented May 2, 2018

I'll close this issue about client-side <ws-*> in a sitelet, which is now fixed on master (and should be released to nuget soon), and open a separate one for the related use case of actually instantiating templates on the server side.

@Tarmil Tarmil closed this May 2, 2018

@Tarmil Tarmil added the 4.2.6.118 label May 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.