Thread overview
Vibe.d navigation
Mar 31, 2020
GreatSam4sure
Mar 31, 2020
GreatSam4sure
Apr 01, 2020
GreatSam4sure
Mar 31, 2020
GreatSam4sure
Mar 31, 2020
JN
March 31, 2020
I am playing with the vibe.d for some days now. One thing I am struggling with is move from one page to another using web interface. The naming of the functions and proper navigation from one page to another is not clear to me.

How to move from one page to another. I will appreciate any help.
March 31, 2020
On 3/31/20 2:57 PM, GreatSam4sure wrote:
> I am playing with the vibe.d for some days now. One thing I am struggling with is move from one page to another using web interface. The naming of the functions and proper navigation from one page to another is not clear to me.
> 
> How to move from one page to another. I will appreciate any help.

I'm not sure what you mean.

Vibe has ways to control the route names of the members of your web interface using UDAs, but primarily uses the name of the functions.

A nice way to see what is registered is to turn the log level to trace when you are setting up your routes, and then set it back to normal during runtime. This prints out all the routes as vibe registers them.

e.g.:

void main()
{
    setLogLevel(LogLevel.trace);
    auto router = new URLRouter();

    ... // set up routes

    auto listener = listenHTTP(settings, router);
    setLogLevel(LogLevel.diagnostic);

    ... // run your event loop
}

If you have more specific examples, I'm glad to help you understand. If you haven't already read it, you should read this page: https://vibed.org/api/vibe.web.web/registerWebInterface

-Steve
March 31, 2020
On Tuesday, 31 March 2020 at 18:57:51 UTC, GreatSam4sure wrote:
> I am playing with the vibe.d for some days now. One thing I am struggling with is move from one page to another using web interface. The naming of the functions and proper navigation from one page to another is not clear to me.
>
> How to move from one page to another. I will appreciate any help.

https://vibed.org/api/vibe.web.web/redirect
March 31, 2020
On Tuesday, 31 March 2020 at 19:34:55 UTC, Steven Schveighoffer wrote:
> On 3/31/20 2:57 PM, GreatSam4sure wrote:
>> I am playing with the vibe.d for some days now. One thing I am struggling with is move from one page to another using web interface. The naming of the functions and proper navigation from one page to another is not clear to me.
>> 
>> How to move from one page to another. I will appreciate any help.
>
> I'm not sure what you mean.
>
> Vibe has ways to control the route names of the members of your web interface using UDAs, but primarily uses the name of the functions.
>
> A nice way to see what is registered is to turn the log level to trace when you are setting up your routes, and then set it back to normal during runtime. This prints out all the routes as vibe registers them.
>
> e.g.:
>
> void main()
> {
>     setLogLevel(LogLevel.trace);
>     auto router = new URLRouter();
>
>     ... // set up routes
>
>     auto listener = listenHTTP(settings, router);
>     setLogLevel(LogLevel.diagnostic);
>
>     ... // run your event loop
> }
>
> If you have more specific examples, I'm glad to help you understand. If you haven't already read it, you should read this page: https://vibed.org/api/vibe.web.web/registerWebInterface
>
> -Steve


Thanks for your reply.

My problem is that I have two views say page1.dt and page2.dt each are HTML 5 pages with head and body. I want to click a button or a link in page to go page 2 vis-a-vis using webinterface. How do I define the web interface functions and how will reference it in the pages




March 31, 2020
On Tuesday, 31 March 2020 at 19:34:55 UTC, Steven Schveighoffer wrote:
> On 3/31/20 2:57 PM, GreatSam4sure wrote:
>> [...]
>
> I'm not sure what you mean.
>
> Vibe has ways to control the route names of the members of your web interface using UDAs, but primarily uses the name of the functions.
>
> A nice way to see what is registered is to turn the log level to trace when you are setting up your routes, and then set it back to normal during runtime. This prints out all the routes as vibe registers them.
>
> e.g.:
>
> void main()
> {
>     setLogLevel(LogLevel.trace);
>     auto router = new URLRouter();
>
>     ... // set up routes
>
>     auto listener = listenHTTP(settings, router);
>     setLogLevel(LogLevel.diagnostic);
>
>     ... // run your event loop
> }
>
> If you have more specific examples, I'm glad to help you understand. If you haven't already read it, you should read this page: https://vibed.org/api/vibe.web.web/registerWebInterface
>
> -Steve



I have a head.dt file that is the head content of all my pages. How can I change the title programmatically. How can change the content of a diet template using code in D?



March 31, 2020
On 3/31/20 4:43 PM, GreatSam4sure wrote:

> Thanks for your reply.
> 
> My problem is that I have two views say page1.dt and page2.dt each are HTML 5 pages with head and body. I want to click a button or a link in page to go page 2 vis-a-vis using webinterface. How do I define the web interface functions and how will reference it in the pages
> 

Vibe does not render templates automatically. You have to render them from a function. The function can be in a route that has nothing to do with the name of the template.

For instance, here is a simple application which uses page1.dt and page2.dt, I have purposely not made the names of the functions different from page1 and page2 to show that they are not related to the routes. I also added a title string which shows how you can pass D symbols to the template:

class WebImpl
{
  void getRouteA(HTTPServerRequest req, HTTPServerResponse res) {
      auto titleVar = "This is page 1";
      res.render!("page1.dt", titleVar);
  }

  void getRouteB(HTTPServerRequest req, HTTPServerResponse res) {
      auto titleVar = "This is page 2";
      res.render!("page2.dt", titleVar);
  }
}

--- views/page1.dt:

doctype html
head
  title #{titleVar}
body
  a(href="route_b") Go to page 2

--- views/page2.dt:

doctype html
head
  title #{titleVar}
body
  a(href="route_a") Go to page 1

here is what your main should look like:

void main()
{
    auto settings = new HTTPServerSettings;
    settings.port = 8080;
    settings.bindAddresses = ["127.0.0.1"];
    auto router = new URLRouter;
    router.registerWebInterface(new WebImpl);
    listenHTTP(settings, router);

    logInfo("Please open http://127.0.0.1:8080/ in your browser.");
    runApplication();
}

As you can see, the routes to the pages are not based on the templates, but based on the names of the functions. getRouteA means use GET method, name of the route is route_a. It is the render function that says "use this template for the current route".

That may be what is confusing you, especially if you come from a framework that matches routes with templates directly.

-Steve
April 01, 2020
On 3/31/20 10:15 PM, Steven Schveighoffer wrote:
> I have purposely not made the names of the functions different from page1 and page2

That should have read I have purposely *made* the names different.

Sorry if that was confusing. I edited my post a lot and didn't reread before posting.

-Steve
April 01, 2020
On Wednesday, 1 April 2020 at 02:15:25 UTC, Steven Schveighoffer wrote:
> On 3/31/20 4:43 PM, GreatSam4sure wrote:
>
>> [...]
>
> Vibe does not render templates automatically. You have to render them from a function. The function can be in a route that has nothing to do with the name of the template.
>
> [...]


Thank you a million times. This is really helpful.