{"action":"created","issue":{"url":"https://api.github.com/repos/mybb/mybb/issues/3046","repository_url":"https://api.github.com/repos/mybb/mybb","labels_url":"https://api.github.com/repos/mybb/mybb/issues/3046/labels{/name}","comments_url":"https://api.github.com/repos/mybb/mybb/issues/3046/comments","events_url":"https://api.github.com/repos/mybb/mybb/issues/3046/events","html_url":"https://github.com/mybb/mybb/pull/3046","id":300981473,"number":3046,"title":"Working on #2972 Template Conversion to Twig Format (header)","user":{"login":"Shade-","id":2552211,"avatar_url":"https://avatars0.githubusercontent.com/u/2552211?v=4","gravatar_id":"","url":"https://api.github.com/users/Shade-","html_url":"https://github.com/Shade-","followers_url":"https://api.github.com/users/Shade-/followers","following_url":"https://api.github.com/users/Shade-/following{/other_user}","gists_url":"https://api.github.com/users/Shade-/gists{/gist_id}","starred_url":"https://api.github.com/users/Shade-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shade-/subscriptions","organizations_url":"https://api.github.com/users/Shade-/orgs","repos_url":"https://api.github.com/users/Shade-/repos","events_url":"https://api.github.com/users/Shade-/events{/privacy}","received_events_url":"https://api.github.com/users/Shade-/received_events","type":"User","site_admin":false},"labels":[{"id":796192405,"url":"https://api.github.com/repos/mybb/mybb/labels/1.9","name":"1.9","color":"fc07c3","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-28T11:04:01Z","updated_at":"2018-02-28T20:09:48Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/mybb/mybb/pulls/3046","html_url":"https://github.com/mybb/mybb/pull/3046","diff_url":"https://github.com/mybb/mybb/pull/3046.diff","patch_url":"https://github.com/mybb/mybb/pull/3046.patch"},"body":"For #2972. Templates converted:\r\n- [x]  header_menu_calendar\r\n- [x]  header_menu_memberlist\r\n- [x]  header_menu_portal\r\n- [x]  header_menu_search\r\n- [x]  header_quicksearch\r\n- [x]  header_welcomeblock_member\r\n- [x]  header_welcomeblock_member_admin\r\n- [x]  header_welcomeblock_member_moderator\r\n- [x]  header_welcomeblock_member_pms\r\n- [x]  header_welcomeblock_member_user\r\n- [x]  header_welcomeblock_member_search\r\n\r\nTwigplates edited and fixed:\r\n- [x]  partials/header.twig (corresponding MyBB template: header)\r\n- [x]  header/welcomeblock_guest.twig (corresponding MyBB template: header_welcomeblock_guest)\r\n\r\nI wasn't sure about the following piece of code:\r\n```php\r\n// Load appropriate welcome block for the current logged in user\r\nif ($mybb->user['uid'] != 0) {\r\n\r\n    // Format the welcome back message\r\n    $lang->welcome_back = $lang->sprintf($lang->welcome_back, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $lastvisit);\r\n\r\n}\r\n// Otherwise, we have a guest\r\nelse {\r\n    switch ($mybb->settings['username_method']) {\r\n        case 0:\r\n            $login_username = $lang->login_username;\r\n            break;\r\n        case 1:\r\n            $login_username = $lang->login_username1;\r\n            break;\r\n        case 2:\r\n            $login_username = $lang->login_username2;\r\n            break;\r\n        default:\r\n            $login_username = $lang->login_username;\r\n            break;\r\n    }\r\n}\r\n```\r\n\r\nI have tried creating a new variable for `build_profile_link(htmlspecialchars_uni($mybb->user['username'])` and `$lastvisit`, but I can't manage to include them in Twig. Also, I have no idea how to handle switch blocks and/or convert them to Twig. @euantorano \r\n\r\nThis PR also fixes an issue in the preliminary conversion of the header template in which the whole guest/member block was included into `div.upper`, causing `div#container` to close earlier than expected and messing up everything on the rest of the page."},"comment":{"url":"https://api.github.com/repos/mybb/mybb/issues/comments/369366919","html_url":"https://github.com/mybb/mybb/pull/3046#issuecomment-369366919","issue_url":"https://api.github.com/repos/mybb/mybb/issues/3046","id":369366919,"user":{"login":"euantorano","id":748913,"avatar_url":"https://avatars1.githubusercontent.com/u/748913?v=4","gravatar_id":"","url":"https://api.github.com/users/euantorano","html_url":"https://github.com/euantorano","followers_url":"https://api.github.com/users/euantorano/followers","following_url":"https://api.github.com/users/euantorano/following{/other_user}","gists_url":"https://api.github.com/users/euantorano/gists{/gist_id}","starred_url":"https://api.github.com/users/euantorano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/euantorano/subscriptions","organizations_url":"https://api.github.com/users/euantorano/orgs","repos_url":"https://api.github.com/users/euantorano/repos","events_url":"https://api.github.com/users/euantorano/events{/privacy}","received_events_url":"https://api.github.com/users/euantorano/received_events","type":"User","site_admin":false},"created_at":"2018-02-28T20:09:48Z","updated_at":"2018-02-28T20:09:48Z","author_association":"OWNER","body":"To get the variables into the views, the easiest way is to add a Twig global. There are a few ways to do this:\r\n\r\n- Create the variables inside a Twig extension. We've been discussing having a new `CoreExtension` that provides various functions like `my_date`, `my_number_format`, etc. so it might make sense to build the global variables used in the header in there, then register them like we do in the `LangExtension`: https://github.com/mybb/mybb/blob/develop/1.9/inc/src/Twig/Extensions/LangExtension.php#L39\r\n- Register the global variable inside `global.php`, using something like:\r\n\r\n```php\r\n$twig = \\MyBB\\app('Twig_Environment');\r\n\r\n$twig->addGlobal('lastVisit', $lastvisit);\r\n``` \r\n\r\nFor that switch, the closest thing is to just use `if`:\r\n\r\n```twig\r\n{% if mybb.settings.username_method == 1 %}\r\n    {{ lang.login_username1 }}\r\n{% elseif mybb.settings.username_method == 2 %}\r\n    {{ lang.login_username2 }}\r\n{% else %}\r\n  {{ lang.login_username }}\r\n{% endif %}\r\n```\r\n\r\nAn alternative would be to use the `attribute()` function, something like:\r\n\r\n```twig\r\n{% if mybb.settings.username_method is in [1, 2] %}\r\n    {{ attribute(lang, 'login_username' ~ mybb.settings.username_method) }}\r\n{% else %}\r\n  {{ lang.login_username }}\r\n{% endif %}\r\n```\r\n\r\nThough the first approach is short enough and easy enough to read in my opinion."}}
{"actor":{"display_login":"euantorano"}}