I have some html segments that are dependant on some values being set in the session, is it possible to condition the inclusion in some way, so that I don't end up duplicating a massive chunk of html code? Or maybe there's another way to go about this that doesn't involve html//1?
foo -->
html([
div(p('I''m always displayed')),
{
http_session_data(Data),
% some other logic
},
div(p('I''m only displayed when there''s session data'))
)].
The code fails: ERROR: [Thread httpd@9999_3] Failed to translate to HTML: http_session_data(Data)
I figured it out by putting the logic in another DCG and include it in html//1.
(
{
http_session_data(Data)
}
->
div(p('I''m only displayed when there''s session data'))
;
{true}
)
The {true}
part is to get rid of an error message in the console.
However, I've since changed my mind and decided to use AngularJS to handle Html since Prolog support for it is too basic and painful for complex DOMs.