Menu

How can I add a UIBlock with $oPage->AddToTab()

2024-03-22
2024-03-22
  • Jacques Dancause

    Good day,

    We have a custom tab for a type of object on our version of iTop.
    I was wondering what I could do to pass a UIBlock into it instead of raw HTML.

    Surely there's some way to convert a UIBlock into HTML? Or another method than AddToTab that can accept UIBlock?

    $oPage->AddToTab(OBJECT_PROPERTIES_TAB, "HelloWorld", "<h1>Test Content, Welcome!</h1>");
    

    This works, but I'm trying to build a form with itop's built in styles.

    function RenderDeploymentsForm($oObject) {
        $input = InputUIBlockFactory::MakeForInputWithLabel("text", "name", "test value");
        return $input; // this is a UIBlock, not HTML, so I can't use it
    }
    

    Any thoughts?

     
  • Guillaume Lajarige

    Hello Jacques,

    If you want to add a UIBlock in a tab, you can do the following:

    // First, save current tab pointer so you can restore it afterwards
    $sPreviousTab = $oPage->GetCurrentTab();
    
    // Then, set current tab pointer to the one you want to add stuff to
    $oPage->SetCurrentTab(OBJECT_PROPERTIES_TAB);
    
    // Then add things to the page directly, it will actually be put within the tab
    $oPage->AddUiBlock($YOUR_UIBLOCK);
    
    // Finally, restore current tab pointer
    $oPage->SetCurrentTab($sPreviousTab);
    

    It's a bit counter-intuitive because you can directly put them in the tab, but it works.

    Hope it helps,
    Guillaume

     
    👍
    2

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.